Commit 37ffee97 authored by Jonathan.Wage's avatar Jonathan.Wage

Moved the tasks from the cli so they are not together.

parent ef40c049
......@@ -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)) {
......
......@@ -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 <jwage@mac.com>
*/
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
......@@ -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 <jwage@mac.com>
*/
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.');
......
......@@ -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 <jwage@mac.com>
*/
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.'),
......
......@@ -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 <jwage@mac.com>
*/
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(),
......
......@@ -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 <jwage@mac.com>
*/
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.',
......
......@@ -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 <jwage@mac.com>
*/
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',
......
......@@ -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 <jwage@mac.com>
*/
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.'),
......
......@@ -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 <jwage@mac.com>
*/
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.',
......
......@@ -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 <jwage@mac.com>
*/
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.',
......
......@@ -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 <jwage@mac.com>
*/
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.'),
......
......@@ -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 <jwage@mac.com>
*/
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.',
......
......@@ -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 <jwage@mac.com>
*/
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.',
......
......@@ -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 <jwage@mac.com>
*/
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.'),
......
......@@ -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 <jwage@mac.com>
*/
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(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment