Init of the app
This commit is contained in:
parent
6159260b29
commit
98c1952938
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
tags
|
||||
vendor
|
||||
composer.lock
|
||||
*.swp
|
13
bin/console
Executable file
13
bin/console
Executable 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
12
composer.json
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"": "src/"
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"symfony/filesystem": "^2.7",
|
||||
"symfony/finder": "^2.7",
|
||||
"symfony/console": "^2.7"
|
||||
}
|
||||
}
|
BIN
src/Deblan/.Application.php.swp
Normal file
BIN
src/Deblan/.Application.php.swp
Normal file
Binary file not shown.
58
src/Deblan/Application.php
Normal file
58
src/Deblan/Application.php
Normal 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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in a new issue