From 0ee402698eb21a691b7984de0e53cf905f57a4ab Mon Sep 17 00:00:00 2001 From: Guilhem Niot Date: Sun, 6 Aug 2017 14:15:02 +0200 Subject: [PATCH 1/4] [HttpKernel] Deprecated commands auto-registration --- UPGRADE-3.4.md | 29 +++++++++++++++++++ UPGRADE-4.0.md | 26 +++++++++++++++++ .../Component/HttpKernel/Bundle/Bundle.php | 2 ++ src/Symfony/Component/HttpKernel/CHANGELOG.md | 1 + .../HttpKernel/Tests/Bundle/BundleTest.php | 4 +++ 5 files changed, 62 insertions(+) diff --git a/UPGRADE-3.4.md b/UPGRADE-3.4.md index 1f15a45d18ea3..ee786eadbd6db 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 commands auto-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 commands registration + ``` + + 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 e0fdf18eda5c9..990866f93ca02 100644 --- a/UPGRADE-4.0.md +++ b/UPGRADE-4.0.md @@ -452,6 +452,32 @@ HttpFoundation HttpKernel ---------- + * Relying on commands auto-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 commands registration + ``` + + 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/Component/HttpKernel/Bundle/Bundle.php b/src/Symfony/Component/HttpKernel/Bundle/Bundle.php index 0b0ea088dcc37..9fb1ae4018230 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 6c21cb722aec3..ca26a6c5bdde6 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 eeefccab81dd0..7abddcca0eee8 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(); From 669d3449733c4224b2a0260e0aca7b73eb8999b0 Mon Sep 17 00:00:00 2001 From: Guilhem Niot Date: Sun, 6 Aug 2017 16:25:58 +0200 Subject: [PATCH 2/4] fixes --- UPGRADE-3.4.md | 4 ++-- UPGRADE-4.0.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/UPGRADE-3.4.md b/UPGRADE-3.4.md index ee786eadbd6db..6ac3eed3663f0 100644 --- a/UPGRADE-3.4.md +++ b/UPGRADE-3.4.md @@ -117,8 +117,8 @@ FrameworkBundle HttpKernel ---------- - * Relying on commands auto-discovery has been deprecated and won't be supported - in 4.0. Use PSR-4 based Service Discovery instead. + * 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: diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md index 990866f93ca02..dd2b7f5ea2ec5 100644 --- a/UPGRADE-4.0.md +++ b/UPGRADE-4.0.md @@ -452,8 +452,8 @@ HttpFoundation HttpKernel ---------- - * Relying on commands auto-discovery has been deprecated and won't be supported - in 4.0. Use PSR-4 based Service Discovery instead. + * Relying on convention-based commands discovery is not supported anymore. + Use PSR-4 based Service Discovery instead. Before: From 1da8b126f86d7f8af55d5b14011d5eb949afcd96 Mon Sep 17 00:00:00 2001 From: Guilhem Niot Date: Wed, 9 Aug 2017 12:51:59 +0200 Subject: [PATCH 3/4] Service Discovery -> service discovery --- UPGRADE-3.4.md | 2 +- UPGRADE-4.0.md | 4 ++-- src/Symfony/Component/HttpKernel/Bundle/Bundle.php | 2 +- src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/UPGRADE-3.4.md b/UPGRADE-3.4.md index 6ac3eed3663f0..a6aea266dae98 100644 --- a/UPGRADE-3.4.md +++ b/UPGRADE-3.4.md @@ -118,7 +118,7 @@ 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. + won't be supported in 4.0. Use PSR-4 based service discovery instead. Before: diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md index dd2b7f5ea2ec5..dd18fa57dd454 100644 --- a/UPGRADE-4.0.md +++ b/UPGRADE-4.0.md @@ -453,7 +453,7 @@ HttpKernel ---------- * Relying on convention-based commands discovery is not supported anymore. - Use PSR-4 based Service Discovery instead. + Use PSR-4 based service discovery instead. Before: @@ -462,7 +462,7 @@ HttpKernel services: # ... - # implicit commands registration + # implicit registration of all commands in the `Command` folder ``` After: diff --git a/src/Symfony/Component/HttpKernel/Bundle/Bundle.php b/src/Symfony/Component/HttpKernel/Bundle/Bundle.php index 9fb1ae4018230..d0ea99f5fa95e 100644 --- a/src/Symfony/Component/HttpKernel/Bundle/Bundle.php +++ b/src/Symfony/Component/HttpKernel/Bundle/Bundle.php @@ -191,7 +191,7 @@ 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); + @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/Tests/Bundle/BundleTest.php b/src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php index 7abddcca0eee8..8e52b097d6946 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php @@ -33,7 +33,7 @@ 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. + * @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() { From 01bf469eafac190ed242e896070a94475836fbd5 Mon Sep 17 00:00:00 2001 From: Guilhem Niot Date: Wed, 9 Aug 2017 12:56:36 +0200 Subject: [PATCH 4/4] Fix tests --- UPGRADE-3.4.md | 2 +- .../SecurityBundle/Tests/Functional/app/Acl/doctrine.yml | 5 +++++ .../SecurityBundle/Tests/Functional/app/AppKernel.php | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) 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 a6aea266dae98..7164e789a808a 100644 --- a/UPGRADE-3.4.md +++ b/UPGRADE-3.4.md @@ -127,7 +127,7 @@ HttpKernel services: # ... - # implicit commands registration + # implicit registration of all commands in the `Command` folder ``` After: 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 0000000000000..7a12388398f76 --- /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 1aab514f45450..82c8ad4aa6c60 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()