Skip to content

Commit 6959dfa

Browse files
author
Robin Chalas
committed
[HttpKernel] Remove convention based commands registration
1 parent 9295a4f commit 6959dfa

File tree

4 files changed

+2
-75
lines changed

4 files changed

+2
-75
lines changed

src/Symfony/Component/HttpKernel/Bundle/Bundle.php

+1-39
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
1616
use Symfony\Component\DependencyInjection\Container;
1717
use Symfony\Component\Console\Application;
18-
use Symfony\Component\Finder\Finder;
1918
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
2019

2120
/**
@@ -153,49 +152,12 @@ final public function getName()
153152
}
154153

155154
/**
156-
* Finds and registers Commands.
157-
*
158-
* Override this method if your bundle commands do not follow the conventions:
159-
*
160-
* * Commands are in the 'Command' sub-directory
161-
* * Commands extend Symfony\Component\Console\Command\Command
155+
* Registers console commands.
162156
*
163157
* @param Application $application An Application instance
164158
*/
165159
public function registerCommands(Application $application)
166160
{
167-
if (!is_dir($dir = $this->getPath().'/Command')) {
168-
return;
169-
}
170-
171-
if (!class_exists('Symfony\Component\Finder\Finder')) {
172-
throw new \RuntimeException('You need the symfony/finder component to register bundle commands.');
173-
}
174-
175-
$finder = new Finder();
176-
$finder->files()->name('*Command.php')->in($dir);
177-
178-
$prefix = $this->getNamespace().'\\Command';
179-
foreach ($finder as $file) {
180-
$ns = $prefix;
181-
if ($relativePath = $file->getRelativePath()) {
182-
$ns .= '\\'.str_replace('/', '\\', $relativePath);
183-
}
184-
$class = $ns.'\\'.$file->getBasename('.php');
185-
if ($this->container) {
186-
$commandIds = $this->container->hasParameter('console.command.ids') ? $this->container->getParameter('console.command.ids') : array();
187-
$alias = 'console.command.'.strtolower(str_replace('\\', '_', $class));
188-
if (isset($commandIds[$alias]) || $this->container->has($alias)) {
189-
continue;
190-
}
191-
}
192-
$r = new \ReflectionClass($class);
193-
if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract() && !$r->getConstructor()->getNumberOfRequiredParameters()) {
194-
@trigger_error(sprintf('Auto-registration of the command "%s" is deprecated since Symfony 3.4 and won\'t be supported in 4.0. Use PSR-4 based service discovery instead.', $class), E_USER_DEPRECATED);
195-
196-
$application->add($r->newInstance());
197-
}
198-
}
199161
}
200162

201163
/**

src/Symfony/Component/HttpKernel/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ CHANGELOG
2020
* support for the `X-Status-Code` when handling exceptions in the `HttpKernel`
2121
has been dropped, use the `HttpKernel::allowCustomResponseCode()` method
2222
instead
23+
* removed convention-based commands registration
2324

2425
3.4.0
2526
-----

src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php

-35
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@
1212
namespace Symfony\Component\HttpKernel\Tests\Bundle;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Component\DependencyInjection\ContainerBuilder;
1615
use Symfony\Component\HttpKernel\Bundle\Bundle;
1716
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionNotValidBundle\ExtensionNotValidBundle;
1817
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\ExtensionPresentBundle;
19-
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionAbsentBundle\ExtensionAbsentBundle;
20-
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand;
2118

2219
class BundleTest extends TestCase
2320
{
@@ -31,24 +28,6 @@ public function testGetContainerExtension()
3128
);
3229
}
3330

34-
/**
35-
* @group legacy
36-
* @expectedDeprecation Auto-registration of the command "Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand" is deprecated since Symfony 3.4 and won't be supported in 4.0. Use PSR-4 based service discovery instead.
37-
*/
38-
public function testRegisterCommands()
39-
{
40-
$cmd = new FooCommand();
41-
$app = $this->getMockBuilder('Symfony\Component\Console\Application')->getMock();
42-
$app->expects($this->once())->method('add')->with($this->equalTo($cmd));
43-
44-
$bundle = new ExtensionPresentBundle();
45-
$bundle->registerCommands($app);
46-
47-
$bundle2 = new ExtensionAbsentBundle();
48-
49-
$this->assertNull($bundle2->registerCommands($app));
50-
}
51-
5231
/**
5332
* @expectedException \LogicException
5433
* @expectedExceptionMessage must implement Symfony\Component\DependencyInjection\Extension\ExtensionInterface
@@ -59,20 +38,6 @@ public function testGetContainerExtensionWithInvalidClass()
5938
$bundle->getContainerExtension();
6039
}
6140

62-
public function testHttpKernelRegisterCommandsIgnoresCommandsThatAreRegisteredAsServices()
63-
{
64-
$container = new ContainerBuilder();
65-
$container->register('console.command.symfony_component_httpkernel_tests_fixtures_extensionpresentbundle_command_foocommand', 'Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand');
66-
67-
$application = $this->getMockBuilder('Symfony\Component\Console\Application')->getMock();
68-
// add() is never called when the found command classes are already registered as services
69-
$application->expects($this->never())->method('add');
70-
71-
$bundle = new ExtensionPresentBundle();
72-
$bundle->setContainer($container);
73-
$bundle->registerCommands($application);
74-
}
75-
7641
public function testBundleNameIsGuessedFromClass()
7742
{
7843
$bundle = new GuessedNameBundle();

src/Symfony/Component/HttpKernel/composer.json

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"symfony/dependency-injection": "~3.4|~4.0",
3232
"symfony/dom-crawler": "~3.4|~4.0",
3333
"symfony/expression-language": "~3.4|~4.0",
34-
"symfony/finder": "~3.4|~4.0",
3534
"symfony/process": "~3.4|~4.0",
3635
"symfony/routing": "~3.4|~4.0",
3736
"symfony/stopwatch": "~3.4|~4.0",

0 commit comments

Comments
 (0)