1
0
Fork 0

Simplifying how composer initializes its commands

pull/12/head
Ryan Weaver 2011-09-15 06:58:57 -05:00
parent cf11b48306
commit b1fcbe9dde
1 changed files with 3 additions and 15 deletions

View File

@ -17,6 +17,7 @@ use Composer\Composer;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Finder\Finder;
use Composer\Command\InstallCommand;
/**
* The console application that handles the commands
@ -58,23 +59,10 @@ class Application extends BaseApplication
}
/**
* Looks for all *Command files in Composer's Command directory
* Initializes all the composer commands
*/
protected function registerCommands()
{
$dir = __DIR__.'/../Command';
$finder = new Finder();
$finder->files()->name('*Command.php')->in($dir);
foreach ($finder as $file) {
$ns = 'Composer\\Command';
if ($relativePath = $file->getRelativePath()) {
$ns .= '\\'.strtr($relativePath, '/', '\\');
}
$r = new \ReflectionClass($ns.'\\'.$file->getBasename('.php'));
if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract()) {
$this->add($r->newInstance());
}
}
$this->add(new InstallCommand());
}
}