class CollectionBuilder extends BaseTask implements NestedCollectionInterface, WrappedTaskInterface, CommandInterface, StateAwareInterface, InputAwareInterface (View source)

Creates a collection, and adds tasks to it. The collection builder offers a streamlined chained-initialization mechanism for easily creating task groups. Facilities for creating working and temporary directories are also provided.

<?php
$result = $this->collectionBuilder()
  ->taskFilesystemStack()
    ->mkdir('g')
    ->touch('g/g.txt')
  ->rollback(
    $this->taskDeleteDir('g')
  )
  ->taskFilesystemStack()
    ->mkdir('g/h')
    ->touch('g/h/h.txt')
  ->taskFilesystemStack()
    ->mkdir('g/h/i/c')
    ->touch('g/h/i/i.txt')
  ->run()
?>

In the example above, the `taskDeleteDir` will be called if

Traits

Task input/output methods. TaskIO is 'used' in BaseTask, so any task that extends this class has access to all of the methods here.

Task input/output methods. TaskIO is 'used' in BaseTask, so any task that extends this class has access to all of the methods here.

LoggerAwareTrait

Properties

protected ConfigInterface $config from  ConfigAwareTrait
protected OutputAdapterInterface $outputAdapter from  VerbosityThresholdTrait
protected int $verbosityThreshold from  VerbosityThresholdTrait
protected OutputInterface $output from  OutputAwareTrait
protected TimeKeeper|null $timer from  Timer
protected null|ProgressIndicator $progressIndicator from  ProgressIndicatorAwareTrait
protected Data $state from  StateAwareTrait
protected InputInterface $input from  InputAwareTrait
protected Tasks $commandFile
protected CollectionInterface $collection
protected TaskInterface $currentTask
protected bool $simulated

Methods

$this
setConfig(ConfigInterface $config)

Set the config management object.

ConfigInterface
getConfig()

Get the config management object.

static string
configPrefix()

Any class that uses ConfigAwareTrait SHOULD override this method , and define a prefix for its configuration items. This is usually done in a base class. When used, this method should return a string that ends with a "."; see BaseTask::configPrefix().

static 
configClassIdentifier($classname)

No description

static 
configPostfix()

No description

static 
configure(string $key, mixed $value, ConfigInterface|null $config = null)

No description

mixed|null
getConfigValue(string $key, mixed|null $default = null)

No description

$this
setVerbosityThreshold(int $verbosityThreshold)

No description

int
verbosityThreshold()

No description

bool
hasOutputAdapter()

No description

writeMessage(string $message)

Print a message if the selected verbosity level is over this task's verbosity threshold.

$this
setOutput(OutputInterface $output)

No description

OutputInterface
output()

No description

OutputInterface
stderr()

No description

OutputInterface
getOutput() deprecated

Backwards compatibility

null|LoggerInterface
logger() deprecated

No description

from  TaskIO
printTaskInfo(string $text, null|array $context = null)

Print information about a task in progress.

from  TaskIO
printTaskSuccess(string $text, null|array $context = null)

Provide notification that some part of the task succeeded.

from  TaskIO
printTaskWarning(string $text, null|array $context = null)

Provide notification that there is something wrong, but execution can continue.

from  TaskIO
printTaskError(string $text, null|array $context = null)

Provide notification that some operation in the task failed, and the task cannot continue.

from  TaskIO
printTaskDebug($text, null|array $context = null)

Provide debugging notification. These messages are only displayed if the log level is VERBOSITY_DEBUG.

from  TaskIO
printTaskOutput(string $level, string $text, null|array $context) deprecated

No description

from  TaskIO
bool
hideTaskProgress()

No description

from  TaskIO
showTaskProgress(bool $inProgress)

No description

from  TaskIO
string
formatBytes(int $size, int $precision = 2)

Format a quantity of bytes.

from  TaskIO
string
getPrintedTaskName(null|object $task = null)

Get the formatted task name for use in task output.

from  TaskIO
array
getTaskContext(null|array $context = null)

No description

from  TaskIO
startTimer()

No description

from  Timer
stopTimer()

No description

from  Timer
resetTimer()

No description

from  Timer
float|null
getExecutionTime()

No description

from  Timer
$this
setProgressIndicator(null|ProgressIndicator $progressIndicator)

No description

null|bool
hideProgressIndicator()

No description

restoreProgressIndicator(bool $visible)

No description

bool
inProgress()

No description

advanceProgressIndicator(int $steps = 1)

No description

$this
inflect(InflectionInterface|mixed $parent)

Ask the provided parent class to inject all of the dependencies that it has and we need.

injectDependencies(mixed $child)

Take all dependencies availble to this task and inject any that are needed into the provided task. The general pattern is that, for every FooAwareInterface that this class implements, it should test to see if the child also implements the same interface, and if so, should call $child->setFoo($this->foo).

getState()

No description

setState(Data $state)

No description

setStateValue(int|string $key, mixed $value)

No description

updateState(Data $update)

No description

resetState()

No description

$this
setInput(InputInterface $input)

No description

InputInterface
input()

No description

InputInterface
getInput() deprecated

Backwards compatibility.

__construct(Tasks $commandFile)

No description

create(ContainerInterface $container, Tasks $commandFile)

No description

$this
simulated(bool $simulated = true)

No description

bool
isSimulated()

No description

string
tmpDir(string $prefix = 'tmp', string $base = '', bool $includeRandomPart = true)

Create a temporary directory to work in. When the collection completes or rolls back, the temporary directory will be deleted.

string
workDir(string $finalDestination)

Create a working directory to hold results. A temporary directory is first created to hold the intermediate results. After the builder finishes, the work directory is moved into its final location; any results already in place will be moved out of the way and then deleted.

$this
addTask(TaskInterface $task)

No description

$this
addCode(callable $code, int|string $name = \Robo\Collection\CollectionInterface::UNNAMEDTASK)

Add arbitrary code to execute as a task.

$this
addTaskList(array $tasks)

Add a list of tasks to our task collection.

$this
rollback(TaskInterface $task)

No description

$this
rollbackCode(callable $rollbackCode)

No description

$this
completion(TaskInterface $task)

No description

$this
completionCode(callable $completionCode)

No description

$this
progressMessage(string $text, array $context = [], string $level = LogLevel::NOTICE)

No description

$this
setParentCollection(NestedCollectionInterface $parentCollection)

No description

$this
addTaskToCollection(TaskInterface $task)

Called by the factory method of each task; adds the current task to the task builder.

$this
storeState(int|string $key, mixed $source = '')

No description

$this
deferTaskConfiguration(string $functionName, int|string $stateKey)

No description

$this
defer($callback)

No description

$this
callCollectionStateFunction(string $functionName, array $args)

No description

$this
callCollectionStateFuntion(string $functionName, array $args) deprecated

No description

getCollectionBuilderCurrentTask()

Return the current task for this collection builder.

newBuilder()

Create a new builder with its own task collection

$this|mixed
__call(string $fn, array $args)

Calling the task builder with methods of the current task calls through to that method of the task.

$this
build(string|object $name, array $args)

Construct the desired task and add it to this builder.

fixTask(TaskInterface $task, array $args)

No description

configureTask(string $taskClass, TaskInterface $task)

Check to see if there are any setter methods defined in configuration for this task.

run()

When we run the collection builder, run everything in the collection.

runTasks()

If there is a single task, run it; if there is a collection, run all of its tasks.

string
getCommand()

Returns command that can be executed.

original()

No description

getCollection()

Return the collection of tasks associated with this builder.

Details

$this setConfig(ConfigInterface $config)

Set the config management object.

Parameters

ConfigInterface $config

Return Value

$this

ConfigInterface getConfig()

Get the config management object.

Return Value

ConfigInterface

static protected string configPrefix()

Any class that uses ConfigAwareTrait SHOULD override this method , and define a prefix for its configuration items. This is usually done in a base class. When used, this method should return a string that ends with a "."; see BaseTask::configPrefix().

Return Value

string

static protected configClassIdentifier($classname)

No description

Parameters

$classname

static protected configPostfix()

No description

static configure(string $key, mixed $value, ConfigInterface|null $config = null)

No description

Parameters

string $key
mixed $value
ConfigInterface|null $config

protected mixed|null getConfigValue(string $key, mixed|null $default = null)

No description

Parameters

string $key
mixed|null $default

Return Value

mixed|null

$this setVerbosityThreshold(int $verbosityThreshold)

No description

Parameters

int $verbosityThreshold

Return Value

$this

int verbosityThreshold()

No description

Return Value

int

setOutputAdapter(OutputAdapterInterface $outputAdapter)

No description

Parameters

OutputAdapterInterface $outputAdapter

bool hasOutputAdapter()

No description

Return Value

bool

bool verbosityMeetsThreshold()

No description

Return Value

bool

writeMessage(string $message)

Print a message if the selected verbosity level is over this task's verbosity threshold.

Parameters

string $message

$this setOutput(OutputInterface $output)

No description

Parameters

OutputInterface $output

Return Value

$this

See also

\Robo\Contract\OutputAwareInterface::setOutput()

protected OutputInterface output()

No description

Return Value

OutputInterface

protected OutputInterface stderr()

No description

Return Value

OutputInterface

protected OutputInterface getOutput() deprecated

deprecated

Backwards compatibility

Return Value

OutputInterface

null|LoggerInterface logger() deprecated

deprecated

No description

Return Value

null|LoggerInterface

protected printTaskInfo(string $text, null|array $context = null)

Print information about a task in progress.

With the Symfony Console logger, NOTICE is displayed at VERBOSITY_VERBOSE and INFO is displayed at VERBOSITY_VERY_VERBOSE.

Robo overrides the default such that NOTICE is displayed at VERBOSITY_NORMAL and INFO is displayed at VERBOSITY_VERBOSE.

n.b. We should probably have printTaskNotice for our ordinary output, and use printTaskInfo for less interesting messages.

Parameters

string $text
null|array $context

protected printTaskSuccess(string $text, null|array $context = null)

Provide notification that some part of the task succeeded.

With the Symfony Console logger, success messages are remapped to NOTICE, and displayed in VERBOSITY_VERBOSE. When used with the Robo logger, success messages are displayed at VERBOSITY_NORMAL.

Parameters

string $text
null|array $context

protected printTaskWarning(string $text, null|array $context = null)

Provide notification that there is something wrong, but execution can continue.

Warning messages are displayed at VERBOSITY_NORMAL.

Parameters

string $text
null|array $context

protected printTaskError(string $text, null|array $context = null)

Provide notification that some operation in the task failed, and the task cannot continue.

Error messages are displayed at VERBOSITY_NORMAL.

Parameters

string $text
null|array $context

protected printTaskDebug($text, null|array $context = null)

Provide debugging notification. These messages are only displayed if the log level is VERBOSITY_DEBUG.

Parameters

$text
null|array $context

protected printTaskOutput(string $level, string $text, null|array $context) deprecated

deprecated

No description

Parameters

string $level

One of the \Psr\Log\LogLevel constant

string $text
null|array $context

protected bool hideTaskProgress()

No description

Return Value

bool

protected showTaskProgress(bool $inProgress)

No description

Parameters

bool $inProgress

protected string formatBytes(int $size, int $precision = 2)

Format a quantity of bytes.

Parameters

int $size
int $precision

Return Value

string

protected string getPrintedTaskName(null|object $task = null)

Get the formatted task name for use in task output.

This is placed in the task context under 'name', and used as the log label by Robo\Common\RoboLogStyle, which is inserted at the head of log messages by Robo\Common\CustomLogStyle::formatMessage().

Parameters

null|object $task

Return Value

string

protected array getTaskContext(null|array $context = null)

No description

Parameters

null|array $context

Return Value

array

Context information.

protected startTimer()

No description

protected stopTimer()

No description

protected resetTimer()

No description

protected float|null getExecutionTime()

No description

Return Value

float|null

int progressIndicatorSteps()

No description

Return Value

int

$this setProgressIndicator(null|ProgressIndicator $progressIndicator)

No description

Parameters

null|ProgressIndicator $progressIndicator

Return Value

$this

protected null|bool hideProgressIndicator()

No description

Return Value

null|bool

protected showProgressIndicator()

No description

protected restoreProgressIndicator(bool $visible)

No description

Parameters

bool $visible

protected int getTotalExecutionTime()

No description

Return Value

int

protected startProgressIndicator()

No description

protected bool inProgress()

No description

Return Value

bool

protected stopProgressIndicator()

No description

protected disableProgressIndicator()

No description

protected detatchProgressIndicator()

No description

protected advanceProgressIndicator(int $steps = 1)

No description

Parameters

int $steps

$this inflect(InflectionInterface|mixed $parent)

Ask the provided parent class to inject all of the dependencies that it has and we need.

Parameters

InflectionInterface|mixed $parent

Return Value

$this

injectDependencies(mixed $child)

Take all dependencies availble to this task and inject any that are needed into the provided task. The general pattern is that, for every FooAwareInterface that this class implements, it should test to see if the child also implements the same interface, and if so, should call $child->setFoo($this->foo).

The benefits of this are pretty large. Any time an object that implements InflectionInterface is created, just call $child->inflect($this), and any available optional dependencies will be hooked up via setter injection.

The required dependencies of an object should be provided via constructor injection, not inflection.

Parameters

mixed $child

An object with one or more *AwareInterfaces implemented.

Data getState()

No description

Return Value

Data

setState(Data $state)

No description

Parameters

Data $state

setStateValue(int|string $key, mixed $value)

No description

Parameters

int|string $key
mixed $value

updateState(Data $update)

No description

Parameters

Data $update

resetState()

No description

$this setInput(InputInterface $input)

No description

Parameters

InputInterface $input

Return Value

$this

See also

\Symfony\Component\Console\Input\InputAwareInterface::setInput()

protected InputInterface input()

No description

Return Value

InputInterface

protected InputInterface getInput() deprecated

deprecated

Backwards compatibility.

Return Value

InputInterface

__construct(Tasks $commandFile)

No description

Parameters

Tasks $commandFile

static CollectionBuilder create(ContainerInterface $container, Tasks $commandFile)

No description

Parameters

ContainerInterface $container
Tasks $commandFile

Return Value

CollectionBuilder

$this simulated(bool $simulated = true)

No description

Parameters

bool $simulated

Return Value

$this

bool isSimulated()

No description

Return Value

bool

string tmpDir(string $prefix = 'tmp', string $base = '', bool $includeRandomPart = true)

Create a temporary directory to work in. When the collection completes or rolls back, the temporary directory will be deleted.

Returns the path to the location where the directory will be created.

Parameters

string $prefix
string $base
bool $includeRandomPart

Return Value

string

string workDir(string $finalDestination)

Create a working directory to hold results. A temporary directory is first created to hold the intermediate results. After the builder finishes, the work directory is moved into its final location; any results already in place will be moved out of the way and then deleted.

Parameters

string $finalDestination

The path where the working directory will be moved once the task collection completes.

Return Value

string

$this addTask(TaskInterface $task)

No description

Parameters

TaskInterface $task

Return Value

$this

$this addCode(callable $code, int|string $name = \Robo\Collection\CollectionInterface::UNNAMEDTASK)

Add arbitrary code to execute as a task.

Parameters

callable $code
int|string $name

Return Value

$this

See also

CollectionInterface::addCode

$this addTaskList(array $tasks)

Add a list of tasks to our task collection.

Parameters

array $tasks

An array of tasks to run with rollback protection

Return Value

$this

$this rollback(TaskInterface $task)

No description

Parameters

TaskInterface $task

Return Value

$this

$this rollbackCode(callable $rollbackCode)

No description

Parameters

callable $rollbackCode

Return Value

$this

$this completion(TaskInterface $task)

No description

Parameters

TaskInterface $task

Return Value

$this

$this completionCode(callable $completionCode)

No description

Parameters

callable $completionCode

Return Value

$this

$this progressMessage(string $text, array $context = [], string $level = LogLevel::NOTICE)

No description

Parameters

string $text
array $context
string $level

Return Value

$this

$this setParentCollection(NestedCollectionInterface $parentCollection)

No description

Parameters

NestedCollectionInterface $parentCollection

Return Value

$this

$this addTaskToCollection(TaskInterface $task)

Called by the factory method of each task; adds the current task to the task builder.

TODO: protected

Parameters

TaskInterface $task

Return Value

$this

$this storeState(int|string $key, mixed $source = '')

No description

Parameters

int|string $key
mixed $source

Return Value

$this

$this deferTaskConfiguration(string $functionName, int|string $stateKey)

No description

Parameters

string $functionName
int|string $stateKey

Return Value

$this

$this defer($callback)

No description

Parameters

$callback

Return Value

$this

protected $this callCollectionStateFunction(string $functionName, array $args)

No description

Parameters

string $functionName
array $args

Return Value

$this

protected $this callCollectionStateFuntion(string $functionName, array $args) deprecated

deprecated Use ::callCollectionStateFunction() instead.

No description

Parameters

string $functionName
array $args

Return Value

$this

TaskInterface getCollectionBuilderCurrentTask()

Return the current task for this collection builder.

TODO: Not needed?

Return Value

TaskInterface

CollectionBuilder newBuilder()

Create a new builder with its own task collection

Return Value

CollectionBuilder

$this|mixed __call(string $fn, array $args)

Calling the task builder with methods of the current task calls through to that method of the task.

There is extra complexity in this function that could be simplified if we attached the 'LoadAllTasks' and custom tasks to the collection builder instead of the RoboFile. While that change would be a better design overall, it would require that the user do a lot more work to set up and use custom tasks. We therefore take on some additional complexity here in order to allow users to maintain their tasks in their RoboFile, which is much more convenient.

Calls to $this->collectionBuilder()->taskFoo() cannot be made directly because all of the task methods are protected. These calls will therefore end up here. If the method name begins with 'task', then it is eligible to be used with the builder.

When we call getBuiltTask, below, it will use the builder attached to the commandfile to build the task. However, this is not what we want: the task needs to be built from THIS collection builder, so that it will be affected by whatever state is active in this builder. To do this, we have two choices: 1) save and restore the builder in the commandfile, or 2) clone the commandfile and set this builder on the copy. 1) is vulnerable to failure in multithreaded environments (currently not supported), while 2) might cause confusion if there is shared state maintained in the commandfile, which is in the domain of the user.

Note that even though we are setting up the commandFile to use this builder, getBuiltTask always creates a new builder (which is constructed using all of the settings from the commandFile's builder), and the new task is added to that. We therefore need to transfer the newly built task into this builder. The temporary builder is discarded.

Parameters

string $fn
array $args

Return Value

$this|mixed

$this build(string|object $name, array $args)

Construct the desired task and add it to this builder.

Parameters

string|object $name
array $args

Return Value

$this

protected CompletionWrapper|Simulator fixTask(TaskInterface $task, array $args)

No description

Parameters

TaskInterface $task
array $args

Return Value

CompletionWrapper|Simulator

protected configureTask(string $taskClass, TaskInterface $task)

Check to see if there are any setter methods defined in configuration for this task.

Parameters

string $taskClass
TaskInterface $task

Result run()

When we run the collection builder, run everything in the collection.

Return Value

Result

protected Result runTasks()

If there is a single task, run it; if there is a collection, run all of its tasks.

Return Value

Result

string getCommand()

Returns command that can be executed.

This method is used to pass generated command from one task to another.

Return Value

string

TaskInterface original()

No description

Return Value

TaskInterface

CollectionInterface getCollection()

Return the collection of tasks associated with this builder.

Return Value

CollectionInterface