Skip to content

Commit d43daa0

Browse files
committed
bug symfony#24630 [WebServerBundle] Prevent commands from being registered by convention (chalasr)
This PR was merged into the 3.4 branch. Discussion ---------- [WebServerBundle] Prevent commands from being registered by convention | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#24629 | License | MIT | Doc PR | n/a Commits ------- 57b7d83 [WebServerBundle] Prevent commands from being registered by convention
2 parents d484f72 + 57b7d83 commit d43daa0

File tree

8 files changed

+48
-10
lines changed

8 files changed

+48
-10
lines changed

src/Symfony/Bundle/WebServerBundle/Command/ServerLogCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class ServerLogCommand extends Command
2929
private $el;
3030
private $handler;
3131

32+
protected static $defaultName = 'server:log';
33+
3234
public function isEnabled()
3335
{
3436
if (!class_exists(ConsoleFormatter::class)) {
@@ -40,8 +42,6 @@ public function isEnabled()
4042

4143
protected function configure()
4244
{
43-
$this->setName('server:log');
44-
4545
if (!class_exists(ConsoleFormatter::class)) {
4646
return;
4747
}

src/Symfony/Bundle/WebServerBundle/Command/ServerRunCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class ServerRunCommand extends ServerCommand
3131
private $documentRoot;
3232
private $environment;
3333

34+
protected static $defaultName = 'server:run';
35+
3436
public function __construct($documentRoot = null, $environment = null)
3537
{
3638
$this->documentRoot = $documentRoot;
@@ -50,7 +52,6 @@ protected function configure()
5052
new InputOption('docroot', 'd', InputOption::VALUE_REQUIRED, 'Document root, usually where your front controllers are stored'),
5153
new InputOption('router', 'r', InputOption::VALUE_REQUIRED, 'Path to custom router script'),
5254
))
53-
->setName('server:run')
5455
->setDescription('Runs a local web server')
5556
->setHelp(<<<'EOF'
5657
<info>%command.name%</info> runs a local web server: By default, the server

src/Symfony/Bundle/WebServerBundle/Command/ServerStartCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class ServerStartCommand extends ServerCommand
3030
private $documentRoot;
3131
private $environment;
3232

33+
protected static $defaultName = 'server:start';
34+
3335
public function __construct($documentRoot = null, $environment = null)
3436
{
3537
$this->documentRoot = $documentRoot;
@@ -44,7 +46,6 @@ public function __construct($documentRoot = null, $environment = null)
4446
protected function configure()
4547
{
4648
$this
47-
->setName('server:start')
4849
->setDefinition(array(
4950
new InputArgument('addressport', InputArgument::OPTIONAL, 'The address to listen to (can be address:port, address, or port)'),
5051
new InputOption('docroot', 'd', InputOption::VALUE_REQUIRED, 'Document root'),

src/Symfony/Bundle/WebServerBundle/Command/ServerStatusCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@
2626
*/
2727
class ServerStatusCommand extends ServerCommand
2828
{
29+
protected static $defaultName = 'server:status';
30+
2931
/**
3032
* {@inheritdoc}
3133
*/
3234
protected function configure()
3335
{
3436
$this
35-
->setName('server:status')
3637
->setDefinition(array(
3738
new InputOption('pidfile', null, InputOption::VALUE_REQUIRED, 'PID file'),
3839
new InputOption('filter', null, InputOption::VALUE_REQUIRED, 'The value to display (one of port, host, or address)'),

src/Symfony/Bundle/WebServerBundle/Command/ServerStopCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@
2525
*/
2626
class ServerStopCommand extends ServerCommand
2727
{
28+
protected static $defaultName = 'server:stop';
29+
2830
/**
2931
* {@inheritdoc}
3032
*/
3133
protected function configure()
3234
{
3335
$this
34-
->setName('server:stop')
3536
->setDefinition(array(
3637
new InputOption('pidfile', null, InputOption::VALUE_REQUIRED, 'PID file'),
3738
))

src/Symfony/Bundle/WebServerBundle/Resources/config/webserver.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,9 @@
2626
<service id="web_server.command.server_status" class="Symfony\Bundle\WebServerBundle\Command\ServerStatusCommand">
2727
<tag name="console.command" command="server:status" />
2828
</service>
29+
30+
<service id="web_server.command.server_log" class="Symfony\Bundle\WebServerBundle\Command\ServerLogCommand">
31+
<tag name="console.command" command="server:log" />
32+
</service>
2933
</services>
3034
</container>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\WebServerBundle\Tests\DependencyInjection;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bundle\WebServerBundle\DependencyInjection\WebServerExtension;
16+
use Symfony\Component\DependencyInjection\ContainerBuilder;
17+
18+
class WebServerExtensionTest extends TestCase
19+
{
20+
public function testLoad()
21+
{
22+
$container = new ContainerBuilder();
23+
(new WebServerExtension())->load(array(), $container);
24+
25+
$this->assertTrue($container->hasDefinition('web_server.command.server_run'));
26+
$this->assertTrue($container->hasDefinition('web_server.command.server_start'));
27+
$this->assertTrue($container->hasDefinition('web_server.command.server_stop'));
28+
$this->assertTrue($container->hasDefinition('web_server.command.server_status'));
29+
$this->assertTrue($container->hasDefinition('web_server.command.server_log'));
30+
}
31+
}

src/Symfony/Bundle/WebServerBundle/composer.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
],
1818
"require": {
1919
"php": "^5.5.9|>=7.0.8",
20-
"symfony/console": "~3.3|~4.0",
20+
"symfony/config": "~3.4|~4.0",
21+
"symfony/console": "~3.4|~4.0",
22+
"symfony/dependency-injection": "~3.4|~4.0",
2123
"symfony/http-kernel": "~3.3|~4.0",
2224
"symfony/process": "~3.3|~4.0"
2325
},
@@ -27,9 +29,6 @@
2729
"/Tests/"
2830
]
2931
},
30-
"conflict": {
31-
"symfony/dependency-injection": "<3.3"
32-
},
3332
"minimum-stability": "dev",
3433
"extra": {
3534
"branch-alias": {

0 commit comments

Comments
 (0)