10000 instantiate valid commands only · symfony/symfony@afad9c7 · GitHub
[go: up one dir, main page]

Skip to content

Commit afad9c7

Browse files
committed
instantiate valid commands only
1 parent bc1bf32 commit afad9c7

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Symfony/Component/HttpKernel/Bundle/Bundle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public function registerCommands(Application $application)
189189
$ns .= '\\'.strtr($relativePath, '/', '\\');
190190
}
191191
$r = new \ReflectionClass($ns.'\\'.$file->getBasename('.php'));
192-
if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract()) {
192+
if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract() && !$r->getConstructor()->getNumberOfRequiredParameters()) {
193193
$application->add($r->newInstance());
194194
}
195195
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command;
4+
5+
use Symfony\Component\Console\Command\Command;
6+
7+
/**
8+
* This command has a required parameter on the constructor and will be ignored by the default Bundle implementation.
9+
*
10+
* @see Symfony\Component\HttpKernel\Bundle\Bundle::registerCommands
11+
*/
12+
class BarCommand extends Command
13+
{
14+
public function __construct($example, $name = 'bar')
15+
{
16+
17+
}
18+
}

0 commit comments

Comments
 (0)
0