[HttpKernel] Deprecated commands auto-registration

This commit is contained in:
Guilhem Niot 2017-08-06 14:15:02 +02:00 committed by Tobias Schultze
parent 736f0d0d93
commit 14215d8185
7 changed files with 73 additions and 0 deletions

View File

@ -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
-------

View File

@ -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.

View File

@ -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]

View File

@ -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 @@ class AppKernel extends Kernel
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()

View File

@ -191,6 +191,8 @@ abstract class Bundle implements BundleInterface
}
$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());
}
}

View File

@ -4,6 +4,7 @@ CHANGELOG
3.4.0
-----
* deprecated commands auto registration
* added `AddCacheClearerPass`
* added `AddCacheWarmerPass`

View File

@ -31,6 +31,10 @@ class BundleTest extends TestCase
);
}
/**
* @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();