diff --git a/lib/Doctrine/Cli.php b/lib/Doctrine/Cli.php index 9b2867154..3742ec6aa 100644 --- a/lib/Doctrine/Cli.php +++ b/lib/Doctrine/Cli.php @@ -20,7 +20,7 @@ */ /** - * Doctrine_Cli_Task + * Doctrine_Cli * * @package Doctrine * @subpackage Cli @@ -54,18 +54,18 @@ class Doctrine_Cli $taskName = str_replace('-', '_', $args[1]); unset($args[1]); - $taskClass = 'Doctrine_Cli_Task_' . Doctrine::classify($taskName); + $taskClass = 'Doctrine_Task_' . Doctrine::classify($taskName); if (class_exists($taskClass)) { $taskInstance = new $taskClass(); - $taskInstance->taskName = str_replace('_', '-', Doctrine::tableize(str_replace('Doctrine_Cli_Task_', '', $taskName))); $args = $this->prepareArgs($taskInstance, $args); - $taskInstance->validate($args); + $taskInstance->setArguments($args); - - $taskInstance->execute(); + if ($taskInstance->validate()) { + $taskInstance->execute(); + } } else { throw new Doctrine_Cli_Exception('Cli task could not be found: '.$taskClass); } @@ -119,7 +119,7 @@ class Doctrine_Cli foreach ($tasks as $taskName) { - $className = 'Doctrine_Cli_Task_' . $taskName; + $className = 'Doctrine_Task_' . $taskName; $taskInstance = new $className(); $taskInstance->taskName = str_replace('_', '-', Doctrine::tableize($taskName)); @@ -164,10 +164,10 @@ class Doctrine_Cli public function loadTasks($directory = null) { if ($directory === null) { - $directory = dirname(__FILE__). DIRECTORY_SEPARATOR . 'Cli' . DIRECTORY_SEPARATOR . 'Task'; + $directory = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Task'; } - $parent = new ReflectionClass('Doctrine_Cli_Task'); + $parent = new ReflectionClass('Doctrine_Task'); $tasks = array(); @@ -180,7 +180,7 @@ class Doctrine_Cli if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false) { require_once($file->getPathName()); - $className = 'Doctrine_Cli_Task_' . $e[0]; + $className = 'Doctrine_Task_' . $e[0]; $class = new ReflectionClass($className); if ($class->isSubClassOf($parent)) { diff --git a/lib/Doctrine/Cli/Task.php b/lib/Doctrine/Task.php similarity index 63% rename from lib/Doctrine/Cli/Task.php rename to lib/Doctrine/Task.php index 9cb643ca2..be74786b8 100644 --- a/lib/Doctrine/Cli/Task.php +++ b/lib/Doctrine/Task.php @@ -23,14 +23,14 @@ * Doctrine_Cli_Task * * @package Doctrine - * @subpackage Cli + * @subpackage Task * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.phpdoctrine.com * @since 1.0 * @version $Revision: 2761 $ * @author Jonathan H. Wage */ -abstract class Doctrine_Cli_Task +abstract class Doctrine_Task { public $taskName = null, $description = null, @@ -38,16 +38,39 @@ abstract class Doctrine_Cli_Task $requiredArguments = array(), $optionalArguments = array(); + /** + * __construct + * + * @return void + */ + public function __construct() + { + $this->taskName = str_replace('_', '-', Doctrine::tableize(str_replace('Doctrine_Task_', '', get_class($this)))); + } + + /** + * execute + * + * Override with each task class + * + * @return void + * @author Jonathan H. Wage + */ abstract function execute(); - public function validate($args) + /** + * validate + * + * Validates that all required fields are present + * + * @return void + */ + public function validate() { - $this->arguments = $args; - $requiredArguments = $this->getRequiredArguments(); foreach ($requiredArguments as $arg) { - if (!isset($args[$arg])) { + if (!isset($this->arguments[$arg])) { throw new Doctrine_Cli_Exception('Required arguments missing. The follow arguments are required: ' . implode(', ', $requiredArguments)); } } @@ -55,6 +78,25 @@ abstract class Doctrine_Cli_Task return true; } + /** + * addArgument + * + * @param string $name + * @param string $value + * @return void + */ + public function addArgument($name, $value) + { + $this->arguments[$name] = $value; + } + + /** + * getArgument + * + * @param string $name + * @param string $default + * @return void + */ public function getArgument($name, $default = null) { if (isset($this->arguments[$name])) { @@ -64,53 +106,85 @@ abstract class Doctrine_Cli_Task } } + /** + * getArguments + * + * @return void + */ public function getArguments() { return $this->arguments; } + /** + * setArguments + * + * @param string $args + * @return void + */ + public function setArguments($args) + { + $this->arguments = $args; + } + + /** + * getTaskName + * + * @return void + */ public function getTaskName() { return $this->taskName; } + /** + * getDescription + * + * @return void + */ public function getDescription() { return $this->description; } + /** + * getRequiredArguments + * + * @return void + */ public function getRequiredArguments() { return array_keys($this->requiredArguments); } + /** + * getOptionalArguments + * + * @return void + */ public function getOptionalArguments() { return array_keys($this->optionalArguments); } + /** + * getRequiredArgumentsDescriptions + * + * @return void + */ public function getRequiredArgumentsDescriptions() { return $this->requiredArguments; } + /** + * getOptionalArgumentsDescriptions + * + * @return void + * @author Jonathan H. Wage + */ public function getOptionalArgumentsDescriptions() { return $this->optionalArguments; } - - public function getSyntax() - { - $syntax = './cli ' . $this->getTaskName(); - - if ($required = $this->getRequiredArguments()) { - $syntax .= ' <' . implode('> <', $required) . '>'; - } - - if ($optional = $this->getOptionalArguments()) { - $syntax .= ' <' . implode('> <', $optional) . '>'; - } - - return $syntax; - } } \ No newline at end of file diff --git a/lib/Doctrine/Cli/Task/CreateDb.php b/lib/Doctrine/Task/CreateDb.php similarity index 93% rename from lib/Doctrine/Cli/Task/CreateDb.php rename to lib/Doctrine/Task/CreateDb.php index 58148bc9a..870ce2fee 100644 --- a/lib/Doctrine/Cli/Task/CreateDb.php +++ b/lib/Doctrine/Task/CreateDb.php @@ -20,17 +20,17 @@ */ /** - * Doctrine_Cli_Task_BuildDb + * Doctrine_Task_BuildDb * * @package Doctrine - * @subpackage Cli + * @subpackage Task * @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_CreateDb extends Doctrine_Cli_Task +class Doctrine_Task_CreateDb extends Doctrine_Task { public $description = 'Create database for each of your connections', $optionalArguments = array('connection' => 'Optionally specify a single connection to create the database for.'); diff --git a/lib/Doctrine/Cli/Task/CreateTables.php b/lib/Doctrine/Task/CreateTables.php similarity index 93% rename from lib/Doctrine/Cli/Task/CreateTables.php rename to lib/Doctrine/Task/CreateTables.php index 076c2f685..fd6591a6a 100644 --- a/lib/Doctrine/Cli/Task/CreateTables.php +++ b/lib/Doctrine/Task/CreateTables.php @@ -20,17 +20,17 @@ */ /** - * Doctrine_Cli_Task_CreateTables + * Doctrine_Task_CreateTables * * @package Doctrine - * @subpackage Cli + * @subpackage Task * @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_CreateTables extends Doctrine_Cli_Task +class Doctrine_Task_CreateTables extends Doctrine_Task { public $description = 'Create tables for all existing database connections', $requiredArguments = array('models_path' => 'Specify path to your models directory.'), diff --git a/lib/Doctrine/Cli/Task/DropDb.php b/lib/Doctrine/Task/DropDb.php similarity index 94% rename from lib/Doctrine/Cli/Task/DropDb.php rename to lib/Doctrine/Task/DropDb.php index 4618601c3..8e22227da 100644 --- a/lib/Doctrine/Cli/Task/DropDb.php +++ b/lib/Doctrine/Task/DropDb.php @@ -20,17 +20,17 @@ */ /** - * Doctrine_Cli_Task_DropDb + * Doctrine_Task_DropDb * * @package Doctrine - * @subpackage Cli + * @subpackage Task * @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_DropDb extends Doctrine_Cli_Task +class Doctrine_Task_DropDb extends Doctrine_Task { public $description = 'Drop database for all existing connections', $requiredArguments = array(), diff --git a/lib/Doctrine/Cli/Task/DumpData.php b/lib/Doctrine/Task/DumpData.php similarity index 95% rename from lib/Doctrine/Cli/Task/DumpData.php rename to lib/Doctrine/Task/DumpData.php index 2b071b8cc..8c396f8f6 100644 --- a/lib/Doctrine/Cli/Task/DumpData.php +++ b/lib/Doctrine/Task/DumpData.php @@ -20,17 +20,17 @@ */ /** - * Doctrine_Cli_Task_DumpData + * Doctrine_Task_DumpData * * @package Doctrine - * @subpackage Cli + * @subpackage Task * @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_DumpData extends Doctrine_Cli_Task +class Doctrine_Task_DumpData extends Doctrine_Task { public $description = 'Dump data to a yaml data fixture file.', $requiredArguments = array('data_fixtures_path' => 'Specify path to write the yaml data fixtures file to.', diff --git a/lib/Doctrine/Cli/Task/GenerateMigration.php b/lib/Doctrine/Task/GenerateMigration.php similarity index 93% rename from lib/Doctrine/Cli/Task/GenerateMigration.php rename to lib/Doctrine/Task/GenerateMigration.php index 0ddb8bcce..4684e9935 100644 --- a/lib/Doctrine/Cli/Task/GenerateMigration.php +++ b/lib/Doctrine/Task/GenerateMigration.php @@ -20,17 +20,17 @@ */ /** - * Doctrine_Cli_Task_GenerateMigration + * Doctrine_Task_GenerateMigration * * @package Doctrine - * @subpackage Cli + * @subpackage Task * @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_GenerateMigration extends Doctrine_Cli_Task +class Doctrine_Task_GenerateMigration extends Doctrine_Task { public $description = 'Generate new migration class definition', $requiredArguments = array('class_name' => 'Name of the migration class to generate', diff --git a/lib/Doctrine/Cli/Task/GenerateModelsFromDb.php b/lib/Doctrine/Task/GenerateModelsFromDb.php similarity index 93% rename from lib/Doctrine/Cli/Task/GenerateModelsFromDb.php rename to lib/Doctrine/Task/GenerateModelsFromDb.php index d8343ffcf..3d68fbbcf 100644 --- a/lib/Doctrine/Cli/Task/GenerateModelsFromDb.php +++ b/lib/Doctrine/Task/GenerateModelsFromDb.php @@ -20,17 +20,17 @@ */ /** - * Doctrine_Cli_Task_GenerateModelsFromDb + * Doctrine_Task_GenerateModelsFromDb * * @package Doctrine - * @subpackage Cli + * @subpackage Task * @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_GenerateModelsFromDb extends Doctrine_Cli_Task +class Doctrine_Task_GenerateModelsFromDb extends Doctrine_Task { public $description = 'Generates your Doctrine_Record definitions from your existing database connections.', $requiredArguments = array('models_path' => 'Specify path to your Doctrine_Record definitions.'), diff --git a/lib/Doctrine/Cli/Task/GenerateModelsFromYaml.php b/lib/Doctrine/Task/GenerateModelsFromYaml.php similarity index 93% rename from lib/Doctrine/Cli/Task/GenerateModelsFromYaml.php rename to lib/Doctrine/Task/GenerateModelsFromYaml.php index 2bda59997..798e128db 100644 --- a/lib/Doctrine/Cli/Task/GenerateModelsFromYaml.php +++ b/lib/Doctrine/Task/GenerateModelsFromYaml.php @@ -20,17 +20,17 @@ */ /** - * Doctrine_Cli_Task_GenerateModelsFromYaml + * Doctrine_Task_GenerateModelsFromYaml * * @package Doctrine - * @subpackage Cli + * @subpackage Task * @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_GenerateModelsFromYaml extends Doctrine_Cli_Task +class Doctrine_Task_GenerateModelsFromYaml extends Doctrine_Task { public $description = 'Generates your Doctrine_Record definitions from a Yaml schema file', $requiredArguments = array('yaml_schema_path' => 'Specify the complete directory path to your yaml schema files.', diff --git a/lib/Doctrine/Cli/Task/GenerateSql.php b/lib/Doctrine/Task/GenerateSql.php similarity index 95% rename from lib/Doctrine/Cli/Task/GenerateSql.php rename to lib/Doctrine/Task/GenerateSql.php index 4cb77ef08..c4461b5fa 100644 --- a/lib/Doctrine/Cli/Task/GenerateSql.php +++ b/lib/Doctrine/Task/GenerateSql.php @@ -20,17 +20,17 @@ */ /** - * Doctrine_Cli_Task_GenerateSql + * Doctrine_Task_GenerateSql * * @package Doctrine - * @subpackage Cli + * @subpackage Task * @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_GenerateSql extends Doctrine_Cli_Task +class Doctrine_Task_GenerateSql extends Doctrine_Task { public $description = 'Generate sql for all existing database connections.', $requiredArguments = array('models_path' => 'Specify complete path to your Doctrine_Record definitions.', diff --git a/lib/Doctrine/Cli/Task/GenerateYamlFromDb.php b/lib/Doctrine/Task/GenerateYamlFromDb.php similarity index 92% rename from lib/Doctrine/Cli/Task/GenerateYamlFromDb.php rename to lib/Doctrine/Task/GenerateYamlFromDb.php index b4c81943b..d56e53378 100644 --- a/lib/Doctrine/Cli/Task/GenerateYamlFromDb.php +++ b/lib/Doctrine/Task/GenerateYamlFromDb.php @@ -20,17 +20,17 @@ */ /** - * Doctrine_Cli_Task_GenerateYamlFromDb + * Doctrine_Task_GenerateYamlFromDb * * @package Doctrine - * @subpackage Cli + * @subpackage Task * @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_GenerateYamlFromDb extends Doctrine_Cli_Task +class Doctrine_Task_GenerateYamlFromDb extends Doctrine_Task { public $description = 'Generates a Yaml schema file from an existing database', $requiredArguments = array('yaml_schema_path' => 'Specify the path to your yaml schema files.'), diff --git a/lib/Doctrine/Cli/Task/GenerateYamlFromModels.php b/lib/Doctrine/Task/GenerateYamlFromModels.php similarity index 93% rename from lib/Doctrine/Cli/Task/GenerateYamlFromModels.php rename to lib/Doctrine/Task/GenerateYamlFromModels.php index cfdd64949..0f045985c 100644 --- a/lib/Doctrine/Cli/Task/GenerateYamlFromModels.php +++ b/lib/Doctrine/Task/GenerateYamlFromModels.php @@ -20,17 +20,17 @@ */ /** - * Doctrine_Cli_Task_GenerateYamlFromModels + * Doctrine_Task_GenerateYamlFromModels * * @package Doctrine - * @subpackage Cli + * @subpackage Task * @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_GenerateYamlFromModels extends Doctrine_Cli_Task +class Doctrine_Task_GenerateYamlFromModels extends Doctrine_Task { public $description = 'Generates a Yaml schema file from existing Doctrine_Record definitions', $requiredArguments = array('yaml_schema_path' => 'Specify the complete directory path to your yaml schema files.', diff --git a/lib/Doctrine/Cli/Task/LoadData.php b/lib/Doctrine/Task/LoadData.php similarity index 94% rename from lib/Doctrine/Cli/Task/LoadData.php rename to lib/Doctrine/Task/LoadData.php index 91412e491..b1222d3ac 100644 --- a/lib/Doctrine/Cli/Task/LoadData.php +++ b/lib/Doctrine/Task/LoadData.php @@ -20,17 +20,17 @@ */ /** - * Doctrine_Cli_Task_LoadData + * Doctrine_Task_LoadData * * @package Doctrine - * @subpackage Cli + * @subpackage Task * @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_LoadData extends Doctrine_Cli_Task +class Doctrine_Task_LoadData extends Doctrine_Task { public $description = 'Load data from a yaml data fixture file.', $requiredArguments = array('data_fixtures_path' => 'Specify the complete path to load the yaml data fixtures files from.', diff --git a/lib/Doctrine/Cli/Task/LoadDummyData.php b/lib/Doctrine/Task/LoadDummyData.php similarity index 94% rename from lib/Doctrine/Cli/Task/LoadDummyData.php rename to lib/Doctrine/Task/LoadDummyData.php index 90935db43..15b2e7fac 100644 --- a/lib/Doctrine/Cli/Task/LoadDummyData.php +++ b/lib/Doctrine/Task/LoadDummyData.php @@ -20,17 +20,17 @@ */ /** - * Doctrine_Cli_Task_LoadDummyData + * Doctrine_Task_LoadDummyData * * @package Doctrine - * @subpackage Cli + * @subpackage Task * @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_LoadDummyData extends Doctrine_Cli_Task +class Doctrine_Task_LoadDummyData extends Doctrine_Task { public $description = 'Load data from a yaml data fixture file.', $requiredArguments = array('models_path' => 'Specify path to your Doctrine_Record definitions.'), diff --git a/lib/Doctrine/Cli/Task/Migrate.php b/lib/Doctrine/Task/Migrate.php similarity index 94% rename from lib/Doctrine/Cli/Task/Migrate.php rename to lib/Doctrine/Task/Migrate.php index b825867bf..d2fdaedd1 100644 --- a/lib/Doctrine/Cli/Task/Migrate.php +++ b/lib/Doctrine/Task/Migrate.php @@ -20,17 +20,17 @@ */ /** - * Doctrine_Cli_Task_Migrate + * Doctrine_Task_Migrate * * @package Doctrine - * @subpackage Cli + * @subpackage Task * @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_Migrate extends Doctrine_Cli_Task +class Doctrine_Task_Migrate extends Doctrine_Task { public $description = 'Migrate database to latest version or the specified version', $requiredArguments = array(),