From c24c3f6e47e561cd4af9fc6a15530136986d7a7a Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Tue, 17 Feb 2015 01:18:05 +0100 Subject: [PATCH] Application console --- app/console | 16 +++++++++ src/Deblan/Console/Application.php | 55 ++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100755 app/console create mode 100644 src/Deblan/Console/Application.php diff --git a/app/console b/app/console new file mode 100755 index 0000000..c3684f6 --- /dev/null +++ b/app/console @@ -0,0 +1,16 @@ +#!/usr/bin/env php +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();; diff --git a/src/Deblan/Console/Application.php b/src/Deblan/Console/Application.php new file mode 100644 index 0000000..0f769c1 --- /dev/null +++ b/src/Deblan/Console/Application.php @@ -0,0 +1,55 @@ +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; + } +}