From e80876ccf398a27e647eb86e423a9286219d3db7 Mon Sep 17 00:00:00 2001 From: "Jonathan.Wage" Date: Tue, 9 Oct 2007 22:15:14 +0000 Subject: [PATCH] Fleshed out cli system and added one sample task. --- lib/Doctrine/Cli.php | 22 ++++++++++++++++- lib/Doctrine/Cli/Exception.php | 34 ++++++++++++++++++++++++++ lib/Doctrine/Cli/Task.php | 6 +++-- lib/Doctrine/Cli/Task/Test.php | 44 ++++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 lib/Doctrine/Cli/Exception.php create mode 100644 lib/Doctrine/Cli/Task/Test.php diff --git a/lib/Doctrine/Cli.php b/lib/Doctrine/Cli.php index bc450d3e5..91a1b09bb 100644 --- a/lib/Doctrine/Cli.php +++ b/lib/Doctrine/Cli.php @@ -31,4 +31,24 @@ * @author Jonathan H. Wage */ class Doctrine_Cli -{ } \ No newline at end of file +{ + public function run($args) + { + if (!isset($args[1])) { + throw new Doctrine_Cli_Exception('You must specify the task to execute'); + } + + unset($args[0]); + $taskName = $args[1]; + unset($args[1]); + + $taskClass = 'Doctrine_Cli_Task_' . Doctrine::classify($taskName); + + if (class_exists($taskClass)) { + $taskInstance = new $taskClass(); + $taskInstance->execute($args); + } else { + throw new Doctrine_Cli_Exception('Cli task could not be found: '.$taskClass); + } + } +} \ No newline at end of file diff --git a/lib/Doctrine/Cli/Exception.php b/lib/Doctrine/Cli/Exception.php new file mode 100644 index 000000000..c7bde699d --- /dev/null +++ b/lib/Doctrine/Cli/Exception.php @@ -0,0 +1,34 @@ +. + */ + +/** + * Doctrine_Cli_Exception + * + * @package Doctrine + * @subpackage Cli + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision: 2761 $ + * @author Jonathan H. Wage + */ +class Doctrine_Cli_Exception extends Doctrine_Exception +{ } \ No newline at end of file diff --git a/lib/Doctrine/Cli/Task.php b/lib/Doctrine/Cli/Task.php index aad7a3eac..87f32f66e 100644 --- a/lib/Doctrine/Cli/Task.php +++ b/lib/Doctrine/Cli/Task.php @@ -30,5 +30,7 @@ * @version $Revision: 2761 $ * @author Jonathan H. Wage */ -class Doctrine_Cli_Task -{ } \ No newline at end of file +abstract class Doctrine_Cli_Task +{ + abstract function execute($args); +} \ No newline at end of file diff --git a/lib/Doctrine/Cli/Task/Test.php b/lib/Doctrine/Cli/Task/Test.php new file mode 100644 index 000000000..e23ce04cb --- /dev/null +++ b/lib/Doctrine/Cli/Task/Test.php @@ -0,0 +1,44 @@ +. + */ + +/** + * Doctrine_Cli_Test_Task + * + * @package Doctrine + * @subpackage Cli + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision: 2761 $ + * @author Jonathan H. Wage + */ +class Doctrine_Cli_Task_Test +{ + public function execute($args) + { + $count = 0; + foreach ($args as $arg) { + $count++; + + echo $count.".) ".$arg."\n"; + } + } +} \ No newline at end of file