Doctrine 1.2.4
Doctrine_Task Class Reference

Inherited by Doctrine_Task_BuildAll, Doctrine_Task_BuildAllLoad, Doctrine_Task_BuildAllReload, Doctrine_Task_Compile, Doctrine_Task_CreateDb, Doctrine_Task_CreateTables, Doctrine_Task_Dql, Doctrine_Task_DropDb, Doctrine_Task_DumpData, Doctrine_Task_GenerateMigration, Doctrine_Task_GenerateMigrationsDb, Doctrine_Task_GenerateMigrationsDiff, Doctrine_Task_GenerateMigrationsModels, Doctrine_Task_GenerateModelsDb, Doctrine_Task_GenerateModelsYaml, Doctrine_Task_GenerateSql, Doctrine_Task_GenerateYamlDb, Doctrine_Task_GenerateYamlModels, Doctrine_Task_LoadData, Doctrine_Task_Migrate, and Doctrine_Task_RebuildDb.

Public Member Functions

 __construct ($dispatcher=null)
 
 addArgument ($name, $value)
 
 ask ()
 
 execute ()
 
 getArgument ($name, $default=null)
 
 getArguments ()
 
 getDescription ()
 
 getOptionalArguments ()
 
 getOptionalArgumentsDescriptions ()
 
 getRequiredArguments ()
 
 getRequiredArgumentsDescriptions ()
 
 getTaskName ()
 
 notify ($notification=null)
 
 setArguments (array $args)
 
 validate ()
 

Static Public Member Functions

static deriveTaskName ($className)
 

Protected Member Functions

 setTaskName ($taskName)
 

Static Protected Member Functions

static validateTaskName ($taskName)
 

Detailed Description

Definition at line 35 of file Task.php.

Constructor & Destructor Documentation

Doctrine_Task::__construct (   $dispatcher = null)

__construct

Since this is an abstract classes that extend this must follow a patter of Doctrine_Task_{TASK_NAME} This is what determines the task name for executing it.

Returns
void

Definition at line 52 of file Task.php.

{
$this->dispatcher = $dispatcher;
$taskName = $this->getTaskName();
//Derive the task name only if it wasn't entered at design-time
if (! strlen($taskName)) {
$taskName = self::deriveTaskName(get_class($this));
}
/*
* All task names must be passed through Doctrine_Task::setTaskName() to make sure they're valid. We're most
* interested in validating manually-entered task names, which are as good as arguments.
*/
$this->setTaskName($taskName);
}

Member Function Documentation

Doctrine_Task::addArgument (   $name,
  $value 
)

addArgument

Parameters
string$name
string$value
Returns
void

Definition at line 166 of file Task.php.

{
$this->arguments[$name] = $value;
}
Doctrine_Task::ask ( )

ask

Returns
void

Definition at line 118 of file Task.php.

{
$args = func_get_args();
call_user_func_array(array($this, 'notify'), $args);
$answer = strtolower(trim(fgets(STDIN)));
return $answer;
}
static Doctrine_Task::deriveTaskName (   $className)
static

Returns the name of the task the specified class would implement

N.B. This method does not check if the specified class is actually a Doctrine Task

This is public so we can easily test its reactions to fully-qualified class names, without having to add PHP 5.3-specific test code

Parameters
string$className
Returns
string|bool

Definition at line 81 of file Task.php.

{
$nameParts = explode('\\', $className);
foreach ($nameParts as &$namePart) {
$prefix = __CLASS__ . '_';
$baseName = strpos($namePart, $prefix) === 0 ? substr($namePart, strlen($prefix)) : $namePart;
$namePart = str_replace('_', '-', Doctrine_Inflector::tableize($baseName));
}
return implode('-', $nameParts);
}
Doctrine_Task::execute ( )
abstract

execute

Override with each task class

Returns
void
Doctrine_Task::getArgument (   $name,
  $default = null 
)

getArgument

Parameters
string$name
string$default
Returns
mixed

Definition at line 178 of file Task.php.

{
if (isset($this->arguments[$name]) && $this->arguments[$name] !== null) {
return $this->arguments[$name];
} else {
return $default;
}
}
Doctrine_Task::getArguments ( )

getArguments

Returns
array $arguments

Definition at line 192 of file Task.php.

{
return $this->arguments;
}
Doctrine_Task::getDescription ( )

getDescription

Returns
string $description

Definition at line 255 of file Task.php.

{
return $this->description;
}
Doctrine_Task::getOptionalArguments ( )

getOptionalArguments

Returns
array $optionalArguments

Definition at line 275 of file Task.php.

{
return array_keys($this->optionalArguments);
}
Doctrine_Task::getOptionalArgumentsDescriptions ( )

getOptionalArgumentsDescriptions

Returns
array $optionalArgumentsDescriptions

Definition at line 295 of file Task.php.

{
return $this->optionalArguments;
}
Doctrine_Task::getRequiredArguments ( )

getRequiredArguments

Returns
array $requiredArguments

Definition at line 265 of file Task.php.

{
return array_keys($this->requiredArguments);
}
Doctrine_Task::getRequiredArgumentsDescriptions ( )

getRequiredArgumentsDescriptions

Returns
array $requiredArgumentsDescriptions

Definition at line 285 of file Task.php.

{
return $this->requiredArguments;
}
Doctrine_Task::getTaskName ( )

getTaskName

Returns
string $taskName

Definition at line 245 of file Task.php.

{
return $this->taskName;
}
Doctrine_Task::notify (   $notification = null)

notify

Parameters
string$notification
Returns
void

Definition at line 100 of file Task.php.

{
if (is_object($this->dispatcher) && method_exists($this->dispatcher, 'notify')) {
$args = func_get_args();
return call_user_func_array(array($this->dispatcher, 'notify'), $args);
} else if ( $notification !== null ) {
return $notification;
} else {
return false;
}
}
Doctrine_Task::setArguments ( array  $args)

setArguments

Parameters
array$args
Returns
void

Definition at line 203 of file Task.php.

{
$this->arguments = $args;
}
Doctrine_Task::setTaskName (   $taskName)
protected

Sets the name of the task, the name that's used to invoke it through a CLI

Parameters
string$taskName
Exceptions
InvalidArgumentExceptionIf the task name is invalid

Definition at line 229 of file Task.php.

{
if (! self::validateTaskName($taskName)) {
throw new InvalidArgumentException(
sprintf('The task name "%s", in %s, is invalid', $taskName, get_class($this))
);
}
$this->taskName = $taskName;
}
Doctrine_Task::validate ( )

validate

Validates that all required fields are present

Returns
bool true

Definition at line 146 of file Task.php.

{
$requiredArguments = $this->getRequiredArguments();
foreach ($requiredArguments as $arg) {
if ( ! isset($this->arguments[$arg])) {
return false;
}
}
return true;
}
static Doctrine_Task::validateTaskName (   $taskName)
staticprotected

Returns TRUE if the specified task name is valid, or FALSE otherwise

Parameters
string$taskName
Returns
bool

Definition at line 214 of file Task.php.

{
/*
* This follows the _apparent_ naming convention. The key thing is to prevent the use of characters that would
* break a command string - we definitely can't allow spaces, for example.
*/
return (bool) preg_match('/^[a-z0-9][a-z0-9\-]*$/', $taskName);
}

The documentation for this class was generated from the following file: