From 14215d8185f2fd991955c5e3eda226f2f2ff1ad8 Mon Sep 17 00:00:00 2001 From: Guilhem Niot Date: Sun, 6 Aug 2017 14:15:02 +0200 Subject: [PATCH] [HttpKernel] Deprecated commands auto-registration --- UPGRADE-3.4.md | 29 +++++++++++++++++++ UPGRADE-4.0.md | 26 +++++++++++++++++ .../Tests/Functional/app/Acl/doctrine.yml | 5 ++++ .../Tests/Functional/app/AppKernel.php | 6 ++++ .../Component/HttpKernel/Bundle/Bundle.php | 2 ++ src/Symfony/Component/HttpKernel/CHANGELOG.md | 1 + .../HttpKernel/Tests/Bundle/BundleTest.php | 4 +++ 7 files changed, 73 insertions(+) create mode 100644 src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/Acl/doctrine.yml diff --git a/UPGRADE-3.4.md b/UPGRADE-3.4.md index 1f15a45d18ea..7164e789a808 100644 --- a/UPGRADE-3.4.md +++ b/UPGRADE-3.4.md @@ -114,6 +114,35 @@ FrameworkBundle class has been deprecated and will be removed in 4.0. Use the `Symfony\Component\Translation\DependencyInjection\TranslatorPass` class instead. +HttpKernel +---------- + + * Relying on convention-based commands discovery has been deprecated and + won't be supported in 4.0. Use PSR-4 based service discovery instead. + + Before: + + ```yml + # app/config/services.yml + services: + # ... + + # implicit registration of all commands in the `Command` folder + ``` + + After: + + ```yml + # app/config/services.yml + services: + # ... + + # explicit commands registration + AppBundle\Command: + resource: '../../src/AppBundle/Command/*' + tags: ['console.command'] + ``` + Process ------- diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md index e0fdf18eda5c..dd18fa57dd45 100644 --- a/UPGRADE-4.0.md +++ b/UPGRADE-4.0.md @@ -452,6 +452,32 @@ HttpFoundation HttpKernel ---------- + * Relying on convention-based commands discovery is not supported anymore. + Use PSR-4 based service discovery instead. + + Before: + + ```yml + # app/config/services.yml + services: + # ... + + # implicit registration of all commands in the `Command` folder + ``` + + After: + + ```yml + # app/config/services.yml + services: + # ... + + # explicit commands registration + AppBundle\Command: + resource: '../../src/AppBundle/Command/*' + tags: ['console.command'] + ``` + * Removed the `kernel.root_dir` parameter. Use the `kernel.project_dir` parameter instead. diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/Acl/doctrine.yml b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/Acl/doctrine.yml new file mode 100644 index 000000000000..7a12388398f7 --- /dev/null +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/Acl/doctrine.yml @@ -0,0 +1,5 @@ +# to be removed once https://github.com/doctrine/DoctrineBundle/pull/684 is merged +services: + Doctrine\Bundle\DoctrineBundle\Command\: + resource: "@DoctrineBundle/Command/*" + tags: [console.command] diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php index 1aab514f4545..82c8ad4aa6c6 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php @@ -11,6 +11,7 @@ namespace Symfony\Bundle\SecurityBundle\Tests\Functional\app; +use Doctrine\ORM\Version; use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpKernel\Kernel; @@ -82,6 +83,11 @@ public function getLogDir() public function registerContainerConfiguration(LoaderInterface $loader) { $loader->load($this->rootConfig); + + // to be removed once https://github.com/doctrine/DoctrineBundle/pull/684 is merged + if ('Acl' === $this->testCase && class_exists(Version::class)) { + $loader->load(__DIR__.'/Acl/doctrine.yml'); + } } public function serialize() diff --git a/src/Symfony/Component/HttpKernel/Bundle/Bundle.php b/src/Symfony/Component/HttpKernel/Bundle/Bundle.php index 0b0ea088dcc3..d0ea99f5fa95 100644 --- a/src/Symfony/Component/HttpKernel/Bundle/Bundle.php +++ b/src/Symfony/Component/HttpKernel/Bundle/Bundle.php @@ -191,6 +191,8 @@ public function registerCommands(Application $application) } $r = new \ReflectionClass($class); if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract() && !$r->getConstructor()->getNumberOfRequiredParameters()) { + @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); + $application->add($r->newInstance()); } } diff --git a/src/Symfony/Component/HttpKernel/CHANGELOG.md b/src/Symfony/Component/HttpKernel/CHANGELOG.md index 6c21cb722aec..ca26a6c5bdde 100644 --- a/src/Symfony/Component/HttpKernel/CHANGELOG.md +++ b/src/Symfony/Component/HttpKernel/CHANGELOG.md @@ -4,6 +4,7 @@ CHANGELOG 3.4.0 ----- + * deprecated commands auto registration * added `AddCacheClearerPass` * added `AddCacheWarmerPass` diff --git a/src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php b/src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php index eeefccab81dd..8e52b097d694 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php @@ -31,6 +31,10 @@ public function testGetContainerExtension() ); } + /** + * @group legacy + * @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. + */ public function testRegisterCommands() { $cmd = new FooCommand();