Application console
This commit is contained in:
parent
af647f7549
commit
c24c3f6e47
16
app/console
Executable file
16
app/console
Executable file
|
@ -0,0 +1,16 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Deblan\Console\Application;
|
||||
|
||||
$app = new Application();
|
||||
|
||||
$app->chdir(__DIR__.'/../');
|
||||
|
||||
$app->addCommandsPath('src/Deblan/PowerDNS/Command/', 'PowerDNS\\Command');
|
||||
$app->addCommandsPath('vendor/propel/propel/src/Propel/Generator/Command/', 'Propel\\Generator\\Command');
|
||||
|
||||
$app->loadCommands();
|
||||
$app->run();;
|
55
src/Deblan/Console/Application.php
Normal file
55
src/Deblan/Console/Application.php
Normal file
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace Deblan\Console;
|
||||
|
||||
use ReflectionException;
|
||||
use ReflectionClass;
|
||||
use Symfony\Component\Console\Application as BaseApplication;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
class Application extends BaseApplication
|
||||
{
|
||||
protected $commandsPaths = array();
|
||||
|
||||
public function addCommandsPath($path, $namespace)
|
||||
{
|
||||
$this->commandsPaths[$path] = trim($namespace, '\\');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function chdir($directory)
|
||||
{
|
||||
chdir($directory);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function loadCommands()
|
||||
{
|
||||
foreach ($this->commandsPaths as $path => $namespace) {
|
||||
$finder = new Finder();
|
||||
$finder->name('*Command.php')->in($path);
|
||||
|
||||
foreach ($finder as $file) {
|
||||
$className = $namespace.'\\'.str_replace('.php', '', $file->getFilename());
|
||||
|
||||
try {
|
||||
$reflexion = new ReflectionClass($className);
|
||||
|
||||
if ($reflexion->isInstantiable()) {
|
||||
$command = new $className();
|
||||
|
||||
$this->addCommands(array(
|
||||
$command,
|
||||
));
|
||||
}
|
||||
} catch (ReflectionException $e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue