Skip to content

Commit

Permalink
instantiate valid commands only
Browse files Browse the repository at this point in the history
  • Loading branch information
havvg committed Jun 4, 2013
1 parent bc1bf32 commit afad9c7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/Bundle/Bundle.php
Expand Up @@ -189,7 +189,7 @@ public function registerCommands(Application $application)
$ns .= '\\'.strtr($relativePath, '/', '\\');
}
$r = new \ReflectionClass($ns.'\\'.$file->getBasename('.php'));
if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract()) {
if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract() && !$r->getConstructor()->getNumberOfRequiredParameters()) {
$application->add($r->newInstance());
}
}
Expand Down
@@ -0,0 +1,18 @@
<?php

namespace Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command;

use Symfony\Component\Console\Command\Command;

/**
* This command has a required parameter on the constructor and will be ignored by the default Bundle implementation.
*
* @see Symfony\Component\HttpKernel\Bundle\Bundle::registerCommands
*/
class BarCommand extends Command
{
public function __construct($example, $name = 'bar')
{

}
}

0 comments on commit afad9c7

Please sign in to comment.