Init of the app

This commit is contained in:
Simon Vieille 2015-07-07 13:01:17 +02:00
parent 6159260b29
commit 98c1952938
6 changed files with 87 additions and 0 deletions

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
tags
vendor
composer.lock
*.swp

0
LICENSE Executable file → Normal file
View file

13
bin/console Executable file
View file

@ -0,0 +1,13 @@
#!/usr/bin/env php
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use Deblan\Application;
$app = new Application('LiveCoding CLI', '1');
$app->chdir(__DIR__.'/../');
$app->addCommandsPath('src/Deblan/Command/', 'Deblan\\Command');
$app->loadCommands();
$app->run();

12
composer.json Normal file
View file

@ -0,0 +1,12 @@
{
"autoload": {
"psr-0": {
"": "src/"
}
},
"require": {
"symfony/filesystem": "^2.7",
"symfony/finder": "^2.7",
"symfony/console": "^2.7"
}
}

Binary file not shown.

View file

@ -0,0 +1,58 @@
<?php
namespace Deblan;
use Symfony\Component\Console\Application as BaseApplication;
use Symfony\Component\Finder\Finder;
/**
* Class Application
* @author Simon Vieille
*/
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;
}
}