class Doctrine_Cli (View source)

Command line interface class

Interface for easily executing Doctrine_Task classes from a command line interface

Constants

TASK_BASE_CLASS

The name of the Doctrine Task base class

Properties

protected string $_scriptName

Methods

__construct(array $config = array(), Doctrine_Cli_Formatter $formatter = null)

__construct

setConfig(array $config)

No description

array
getConfig()

No description

setFormatter(Doctrine_Cli_Formatter $formatter)

No description

object
getFormatter()

No description

mixed
getConfigValue(string $name)

Returns the specified value from the config, or the default value, if specified

bool
hasConfigValue(string $name, mixed $value = null, bool $strict = false)

Returns TRUE if the element in the config has the specified value, or FALSE otherwise

setRegisteredTasks(array $registeredTask)

Sets the array of registered tasks

array
getRegisteredTasks()

Returns an array containing the registered tasks

bool
taskClassIsRegistered(string $className)

Returns TRUE if the specified Task-class is registered, or FALSE otherwise

bool
taskNameIsRegistered(string $taskName, string|null $className = null)

Returns TRUE if a task with the specified name is registered, or FALSE otherwise

setTaskInstance(Doctrine_Task $task)

No description

object
getTaskInstance()

No description

includeAndRegisterTaskClasses()

Called by the constructor, this method includes and registers Doctrine core Tasks and then registers all other loaded Task classes

includeAndRegisterDoctrineTaskClasses(mixed $directories = null)

Includes and registers Doctrine-style tasks from the specified directory / directories

array
includeDoctrineTaskClasses(string $directory)

Attempts to include Doctrine-style Task-classes from the specified directory - and nothing more besides

registerTaskClass(string $className)

Registers the specified included task-class

bool
classIsTask(string $className)

Returns TRUE if the specified class is a Task, or FALSE otherwise

object
createTaskInstance(string $className, Doctrine_Cli $cli)

Creates, and returns, a new instance of the specified Task class

registerIncludedTaskClasses()

Registers all loaded classes - by default - or the specified loaded Task classes

void
notify(string $notification = null, string $style = 'HEADER')

Notify the formatter of a message

string
formatExceptionMessage(Exception $exception)

Formats, and then returns, the message in the specified exception

void
notifyException(Exception $exception)

Notify the formatter of an exception

void
run(array $args)

Public function to run the loaded task with the passed arguments

void
_run(array $args)

Run the actual task execution with the passed arguments

executeTask(Doctrine_Task $task, array $preparedArguments)

Executes the task with the specified prepared arguments

array
prepareArgs(array $args)

Prepare the raw arguments for execution. Combines with the required and optional argument list in order to determine a complete array of arguments for the task

printTasks(string|null $taskName = null, bool $full = false)

Prints an index of all the available tasks in the CLI instance

string
assembleArgumentList(array $argumentsDescriptions, array $config, Doctrine_Cli_Formatter $formatter)

No description

loadTasks($directory = null) deprecated

Old method retained for backwards compatibility

_getTaskClassFromArgs(array $args) deprecated

Old method retained for backwards compatibility

getLoadedTasks() deprecated

Old method retained for backwards compatibility

Details

__construct(array $config = array(), Doctrine_Cli_Formatter $formatter = null)

__construct

Parameters

array $config [$config=array()]
Doctrine_Cli_Formatter $formatter [$formatter=null] Doctrine_Cli_Formatter

setConfig(array $config)

Parameters

array $config

array getConfig()

Return Value

array

setFormatter(Doctrine_Cli_Formatter $formatter)

Parameters

Doctrine_Cli_Formatter $formatter Doctrine_Cli_Formatter

object getFormatter()

Return Value

object Doctrine_Cli_Formatter

mixed getConfigValue(string $name)

Returns the specified value from the config, or the default value, if specified

Parameters

string $name

Return Value

mixed

Exceptions

OutOfBoundsException If the element does not exist in the config

bool hasConfigValue(string $name, mixed $value = null, bool $strict = false)

Returns TRUE if the element in the config has the specified value, or FALSE otherwise

If $value is not passed, this method will return TRUE if the specified element has any value, or FALSE if the element is not set

For strict checking, set $strict to TRUE - the default is FALSE

Parameters

string $name
mixed $value [$value=null]
bool $strict [$strict=false]

Return Value

bool

setRegisteredTasks(array $registeredTask)

Sets the array of registered tasks

Parameters

array $registeredTask

array getRegisteredTasks()

Returns an array containing the registered tasks

Return Value

array

bool taskClassIsRegistered(string $className)

Returns TRUE if the specified Task-class is registered, or FALSE otherwise

Parameters

string $className

Return Value

bool

bool taskNameIsRegistered(string $taskName, string|null $className = null)

Returns TRUE if a task with the specified name is registered, or FALSE otherwise

If a matching task is found, $className is set with the name of the implementing class

Parameters

string $taskName
string|null $className [&$className=null]

Return Value

bool

setTaskInstance(Doctrine_Task $task)

Parameters

Doctrine_Task $task Doctrine_Task

object getTaskInstance()

Return Value

object Doctrine_Task

protected includeAndRegisterTaskClasses()

Called by the constructor, this method includes and registers Doctrine core Tasks and then registers all other loaded Task classes

The second round of registering will pick-up loaded custom Tasks. Methods are provided that will allow users to register Tasks loaded after creating an instance of Doctrine_Cli.

protected includeAndRegisterDoctrineTaskClasses(mixed $directories = null)

Includes and registers Doctrine-style tasks from the specified directory / directories

If no directory is given it looks in the default Doctrine/Task folder for the core tasks

Parameters

mixed $directories [$directories=null] Can be a string path or array of paths

protected array includeDoctrineTaskClasses(string $directory)

Attempts to include Doctrine-style Task-classes from the specified directory - and nothing more besides

Returns an array containing the names of Task classes included

This method effectively makes two assumptions: - The directory contains only Task class-files - The class files, and the class in each, follow the Doctrine naming conventions

This means that a file called "Foo.php", say, will be expected to contain a Task class called "Doctrine_Task_Foo". Hence the method's name, "includeDoctrineTaskClasses".

Parameters

string $directory

Return Value

array $taskClassesIncluded

Exceptions

InvalidArgumentException If the directory does not exist

registerTaskClass(string $className)

Registers the specified included task-class

Parameters

string $className

Exceptions

InvalidArgumentException If the class does not exist or the task-name is blank
DomainException If the class is not a Doctrine Task

protected bool classIsTask(string $className)

Returns TRUE if the specified class is a Task, or FALSE otherwise

Parameters

string $className

Return Value

bool

protected object createTaskInstance(string $className, Doctrine_Cli $cli)

Creates, and returns, a new instance of the specified Task class

Displays a message, and returns FALSE, if there were problems instantiating the class

Parameters

string $className
Doctrine_Cli $cli Doctrine_Cli

Return Value

object Doctrine_Task

registerIncludedTaskClasses()

Registers all loaded classes - by default - or the specified loaded Task classes

This method will skip registered task classes, so it can be safely called many times over

void notify(string $notification = null, string $style = 'HEADER')

Notify the formatter of a message

Parameters

string $notification The notification message
string $style Style to format the notification with(INFO, ERROR)

Return Value

void

protected string formatExceptionMessage(Exception $exception)

Formats, and then returns, the message in the specified exception

Parameters

Exception $exception

Return Value

string

protected void notifyException(Exception $exception)

Notify the formatter of an exception

N.B. This should really only be called by Doctrine_Cli::run(). Exceptions should be thrown when errors occur: it's up to Doctrine_Cli::run() to determine how those exceptions are reported.

Parameters

Exception $exception

Return Value

void

void run(array $args)

Public function to run the loaded task with the passed arguments

Parameters

array $args

Return Value

void

Exceptions

Doctrine_Cli_Exception

protected void _run(array $args)

Run the actual task execution with the passed arguments

Parameters

array $args Array of arguments for this task being executed

Return Value

void

Exceptions

Doctrine_Cli_Exception If the requested task has not been registered or if required arguments are missing

protected executeTask(Doctrine_Task $task, array $preparedArguments)

Executes the task with the specified prepared arguments

Parameters

Doctrine_Task $task Doctrine_Task
array $preparedArguments

Exceptions

Doctrine_Cli_Exception If required arguments are missing

protected array prepareArgs(array $args)

Prepare the raw arguments for execution. Combines with the required and optional argument list in order to determine a complete array of arguments for the task

Parameters

array $args Array of raw arguments

Return Value

array $prepared Array of prepared arguments

printTasks(string|null $taskName = null, bool $full = false)

Prints an index of all the available tasks in the CLI instance

Parameters

string|null $taskName [$taskName=null]
bool $full [$full=false]

protected string assembleArgumentList(array $argumentsDescriptions, array $config, Doctrine_Cli_Formatter $formatter)

Parameters

array $argumentsDescriptions
array $config
Doctrine_Cli_Formatter $formatter Doctrine_Cli_Formatter

Return Value

string

loadTasks($directory = null) deprecated

deprecated

Old method retained for backwards compatibility

Parameters

$directory

protected _getTaskClassFromArgs(array $args) deprecated

deprecated

Old method retained for backwards compatibility

Parameters

array $args

getLoadedTasks() deprecated

deprecated

Old method retained for backwards compatibility