Skip to content

Commit

Permalink
feature #23805 [HttpKernel] Deprecated commands auto-registration (Gu…
Browse files Browse the repository at this point in the history
…ilhemN)

This PR was squashed before being merged into the 3.4 branch (closes #23805).

Discussion
----------

[HttpKernel] Deprecated commands auto-registration

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | no <!-- don't forget updating src/**/CHANGELOG.md files -->
| BC breaks?    | no
| Deprecations? | yes <!-- don't forget updating UPGRADE-*.md files -->
| Tests pass?   | yes
| Fixed tickets | #23488
| License       | MIT
| Doc PR        |

Deprecates commands auto-registration. See #23488 for arguments.

Commits
-------

14215d8 [HttpKernel] Deprecated commands auto-registration
  • Loading branch information
Tobion committed Aug 9, 2017
2 parents 1a9a254 + 14215d8 commit 2536345
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 0 deletions.
29 changes: 29 additions & 0 deletions UPGRADE-3.4.md
Expand Up @@ -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
-------

Expand Down
26 changes: 26 additions & 0 deletions UPGRADE-4.0.md
Expand Up @@ -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.

Expand Down
@@ -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]
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/HttpKernel/Bundle/Bundle.php
Expand Up @@ -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());
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/HttpKernel/CHANGELOG.md
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
3.4.0
-----

* deprecated commands auto registration
* added `AddCacheClearerPass`
* added `AddCacheWarmerPass`

Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php
Expand Up @@ -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();
Expand Down

0 comments on commit 2536345

Please sign in to comment.