[WebServerBundle] Prevent commands from being registered by convention

This commit is contained in:
Robin Chalas 2017-10-19 18:26:19 +02:00
parent d484f7282a
commit 57b7d832d9
8 changed files with 48 additions and 10 deletions

View File

@ -29,6 +29,8 @@ class ServerLogCommand extends Command
private $el;
private $handler;
protected static $defaultName = 'server:log';
public function isEnabled()
{
if (!class_exists(ConsoleFormatter::class)) {
@ -40,8 +42,6 @@ class ServerLogCommand extends Command
protected function configure()
{
$this->setName('server:log');
if (!class_exists(ConsoleFormatter::class)) {
return;
}

View File

@ -31,6 +31,8 @@ class ServerRunCommand extends ServerCommand
private $documentRoot;
private $environment;
protected static $defaultName = 'server:run';
public function __construct($documentRoot = null, $environment = null)
{
$this->documentRoot = $documentRoot;
@ -50,7 +52,6 @@ class ServerRunCommand extends ServerCommand
new InputOption('docroot', 'd', InputOption::VALUE_REQUIRED, 'Document root, usually where your front controllers are stored'),
new InputOption('router', 'r', InputOption::VALUE_REQUIRED, 'Path to custom router script'),
))
->setName('server:run')
->setDescription('Runs a local web server')
->setHelp(<<<'EOF'
<info>%command.name%</info> runs a local web server: By default, the server

View File

@ -30,6 +30,8 @@ class ServerStartCommand extends ServerCommand
private $documentRoot;
private $environment;
protected static $defaultName = 'server:start';
public function __construct($documentRoot = null, $environment = null)
{
$this->documentRoot = $documentRoot;
@ -44,7 +46,6 @@ class ServerStartCommand extends ServerCommand
protected function configure()
{
$this
->setName('server:start')
->setDefinition(array(
new InputArgument('addressport', InputArgument::OPTIONAL, 'The address to listen to (can be address:port, address, or port)'),
new InputOption('docroot', 'd', InputOption::VALUE_REQUIRED, 'Document root'),

View File

@ -26,13 +26,14 @@ use Symfony\Component\Console\Style\SymfonyStyle;
*/
class ServerStatusCommand extends ServerCommand
{
protected static $defaultName = 'server:status';
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('server:status')
->setDefinition(array(
new InputOption('pidfile', null, InputOption::VALUE_REQUIRED, 'PID file'),
new InputOption('filter', null, InputOption::VALUE_REQUIRED, 'The value to display (one of port, host, or address)'),

View File

@ -25,13 +25,14 @@ use Symfony\Component\Console\Style\SymfonyStyle;
*/
class ServerStopCommand extends ServerCommand
{
protected static $defaultName = 'server:stop';
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('server:stop')
->setDefinition(array(
new InputOption('pidfile', null, InputOption::VALUE_REQUIRED, 'PID file'),
))

View File

@ -26,5 +26,9 @@
<service id="web_server.command.server_status" class="Symfony\Bundle\WebServerBundle\Command\ServerStatusCommand">
<tag name="console.command" command="server:status" />
</service>
<service id="web_server.command.server_log" class="Symfony\Bundle\WebServerBundle\Command\ServerLogCommand">
<tag name="console.command" command="server:log" />
</service>
</services>
</container>

View File

@ -0,0 +1,31 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\WebServerBundle\Tests\DependencyInjection;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\WebServerBundle\DependencyInjection\WebServerExtension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class WebServerExtensionTest extends TestCase
{
public function testLoad()
{
$container = new ContainerBuilder();
(new WebServerExtension())->load(array(), $container);
$this->assertTrue($container->hasDefinition('web_server.command.server_run'));
$this->assertTrue($container->hasDefinition('web_server.command.server_start'));
$this->assertTrue($container->hasDefinition('web_server.command.server_stop'));
$this->assertTrue($container->hasDefinition('web_server.command.server_status'));
$this->assertTrue($container->hasDefinition('web_server.command.server_log'));
}
}

View File

@ -17,7 +17,9 @@
],
"require": {
"php": "^5.5.9|>=7.0.8",
"symfony/console": "~3.3|~4.0",
"symfony/config": "~3.4|~4.0",
"symfony/console": "~3.4|~4.0",
"symfony/dependency-injection": "~3.4|~4.0",
"symfony/http-kernel": "~3.3|~4.0",
"symfony/process": "~3.3|~4.0"
},
@ -27,9 +29,6 @@
"/Tests/"
]
},
"conflict": {
"symfony/dependency-injection": "<3.3"
},
"minimum-stability": "dev",
"extra": {
"branch-alias": {