-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpKernel] Remove convention based commands registration #23857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,6 @@ | |
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Container; | ||
use Symfony\Component\Console\Application; | ||
use Symfony\Component\Finder\Finder; | ||
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; | ||
|
||
/** | ||
|
@@ -153,49 +152,12 @@ final public function getName() | |
} | ||
|
||
/** | ||
* Finds and registers Commands. | ||
* | ||
* Override this method if your bundle commands do not follow the conventions: | ||
* | ||
* * Commands are in the 'Command' sub-directory | ||
* * Commands extend Symfony\Component\Console\Command\Command | ||
* Registers console commands. | ||
* | ||
* @param Application $application An Application instance | ||
*/ | ||
public function registerCommands(Application $application) | ||
{ | ||
if (!is_dir($dir = $this->getPath().'/Command')) { | ||
return; | ||
} | ||
|
||
if (!class_exists('Symfony\Component\Finder\Finder')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the dep can be removed from composer.json There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is still used elsewhere There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nevermind, I thought I was in FrameworkBundle, done |
||
throw new \RuntimeException('You need the symfony/finder component to register bundle commands.'); | ||
} | ||
|
||
$finder = new Finder(); | ||
$finder->files()->name('*Command.php')->in($dir); | ||
|
||
$prefix = $this->getNamespace().'\\Command'; | ||
foreach ($finder as $file) { | ||
$ns = $prefix; | ||
if ($relativePath = $file->getRelativePath()) { | ||
$ns .= '\\'.str_replace('/', '\\', $relativePath); | ||
} | ||
$class = $ns.'\\'.$file->getBasename('.php'); | ||
if ($this->container) { | ||
$commandIds = $this->container->hasParameter('console.command.ids') ? $this->container->getParameter('console.command.ids') : array(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we deprecate this param as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, it is still used to filter out lazy commands in framework Application There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i see... but after #23796 we could right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure, implementing it would be optional so non lazy command services would still be supported. To be rediscussed at/after it :) |
||
$alias = 'console.command.'.strtolower(str_replace('\\', '_', $class)); | ||
if (isset($commandIds[$alias]) || $this->container->has($alias)) { | ||
continue; | ||
} | ||
} | ||
$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()); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,12 +12,9 @@ | |
namespace Symfony\Component\HttpKernel\Tests\Bundle; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionNotValidBundle\ExtensionNotValidBundle; | ||
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\ExtensionPresentBundle; | ||
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionAbsentBundle\ExtensionAbsentBundle; | ||
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand; | ||
|
||
class BundleTest extends TestCase | ||
{ | ||
|
@@ -31,24 +28,6 @@ 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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would keep this test and assert no command is registered for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure that testing a no-op is useful at all, we don't for others like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here that could prevent mistakes due to merging conflicts. |
||
{ | ||
$cmd = new FooCommand(); | ||
$app = $this->getMockBuilder('Symfony\Component\Console\Application')->getMock(); | ||
$app->expects($this->once())->method('add')->with($this->equalTo($cmd)); | ||
|
||
$bundle = new ExtensionPresentBundle(); | ||
$bundle->registerCommands($app); | ||
|
||
$bundle2 = new ExtensionAbsentBundle(); | ||
|
||
$this->assertNull($bundle2->registerCommands($app)); | ||
} | ||
|
||
/** | ||
* @expectedException \LogicException | ||
* @expectedExceptionMessage must implement Symfony\Component\DependencyInjection\Extension\ExtensionInterface | ||
|
@@ -59,20 +38,6 @@ public function testGetContainerExtensionWithInvalidClass() | |
$bundle->getContainerExtension(); | ||
} | ||
|
||
public function testHttpKernelRegisterCommandsIgnoresCommandsThatAreRegisteredAsServices() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should probably have been flagged as legacy in 3.4. Do we care? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Imo we don't care, no deprecation is triggered here anyway. |
||
{ | ||
$container = new ContainerBuilder(); | ||
$container->register('console.command.symfony_component_httpkernel_tests_fixtures_extensionpresentbundle_command_foocommand', 'Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand'); | ||
|
||
$application = $this->getMockBuilder('Symfony\Component\Console\Application')->getMock(); | ||
// add() is never called when the found command classes are already registered as services | ||
$application->expects($this->never())->method('add'); | ||
|
||
$bundle = new ExtensionPresentBundle(); | ||
$bundle->setContainer($container); | ||
$bundle->registerCommands($application); | ||
} | ||
|
||
public function testBundleNameIsGuessedFromClass() | ||
{ | ||
$bundle = new GuessedNameBundle(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,6 @@ | |
"symfony/dependency-injection": "~3.4|~4.0", | ||
"symfony/dom-crawler": "~3.4|~4.0", | ||
"symfony/expression-language": "~3.4|~4.0", | ||
"symfony/finder": "~3.4|~4.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is one more in "suggest" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
"symfony/process": "~3.4|~4.0", | ||
"symfony/routing": "~3.4|~4.0", | ||
"symfony/stopwatch": "~3.4|~4.0", | ||
|
@@ -51,7 +50,6 @@ | |
"symfony/config": "", | ||
"symfony/console": "", | ||
"symfony/dependency-injection": "", | ||
"symfony/finder": "", | ||
"symfony/var-dumper": "" | ||
}, | ||
"autoload": { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overrides can be removed i guess
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not an override. It is the base definition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TwigBundle::registerCommands etc. They are now noop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not good if you don't change the min version to forbid using TwigBundle 4.0 with HttpKernel 3.4 and the no-op was important though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed, no-ops re-added in bundles