interface CollectionInterface implements NestedCollectionInterface (View source)

Constants

UNNAMEDTASK

Unnamed tasks are assigned an arbitrary numeric index in the task list. Any numeric value may be used, but the UNNAMEDTASK constant is recommended for clarity.

Methods

$this
setParentCollection(NestedCollectionInterface $parentCollection)

No description

$this
add(TaskInterface $task, int|string $name = self::UNNAMEDTASK)

Add a task or a list of tasks to our task collection. Each task will run via its 'run()' method once (and if) all of the tasks added before it complete successfully. If the task also implements RollbackInterface, then it will be rolled back via its 'rollback()' method ONLY if its 'run()' method completes successfully, and some task added after it fails.

$this
addCode(callable $code, int|string $name = self::UNNAMEDTASK)

Add arbitrary code to execute as a task.

$this
addIterable(CollectionInterface|array $iterable, callable $code)

Add arbitrary code that will be called once for every item in the provided array or iterable object. If the function result of the provided callback is a TaskInterface or Collection, then it will be executed.

$this
rollback(TaskInterface $rollbackTask)

Add a rollback task to our task collection. A rollback task will execute ONLY if all of the tasks added before it complete successfully, AND some task added after it fails.

$this
rollbackCode(callable $rollbackTask)

Add arbitrary code to execute as a rollback.

$this
completion(TaskInterface $completionTask)

Add a completion task to our task collection. A completion task will execute EITHER after all tasks succeed, OR immediatley after any task fails. Completion tasks never cause errors to be returned from Collection::run(), even if they fail.

$this
completionCode(callable $completionTask)

Add arbitrary code to execute as a completion.

$this
before(string $name, callable|TaskInterface $task, int|string $nameOfTaskToAdd = self::UNNAMEDTASK)

Add a task before an existing named task.

$this
after(string $name, callable|TaskInterface $task, int|string $nameOfTaskToAdd = self::UNNAMEDTASK)

Add a task after an existing named task.

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

Print a progress message after Collection::run() has executed all of the tasks that were added prior to the point when this method was called. If one of the previous tasks fail, then this message will not be printed.

Details

$this setParentCollection(NestedCollectionInterface $parentCollection)

No description

Parameters

NestedCollectionInterface $parentCollection

Return Value

$this

$this add(TaskInterface $task, int|string $name = self::UNNAMEDTASK)

Add a task or a list of tasks to our task collection. Each task will run via its 'run()' method once (and if) all of the tasks added before it complete successfully. If the task also implements RollbackInterface, then it will be rolled back via its 'rollback()' method ONLY if its 'run()' method completes successfully, and some task added after it fails.

Parameters

TaskInterface $task

The task to add to our collection.

int|string $name

An optional name for the task -- missing or UNNAMEDTASK for unnamed tasks. Names are used for positioning before and after tasks.

Return Value

$this

$this addCode(callable $code, int|string $name = self::UNNAMEDTASK)

Add arbitrary code to execute as a task.

Parameters

callable $code

Code to execute as a task

int|string $name

An optional name for the task -- missing or UNNAMEDTASK for unnamed tasks. Names are used for positioning before and after tasks.

Return Value

$this

$this addIterable(CollectionInterface|array $iterable, callable $code)

Add arbitrary code that will be called once for every item in the provided array or iterable object. If the function result of the provided callback is a TaskInterface or Collection, then it will be executed.

Parameters

CollectionInterface|array $iterable

A collection of things to iterate.

callable $code

A callback function to call for each item in the collection.

Return Value

$this

$this rollback(TaskInterface $rollbackTask)

Add a rollback task to our task collection. A rollback task will execute ONLY if all of the tasks added before it complete successfully, AND some task added after it fails.

Parameters

TaskInterface $rollbackTask

The rollback task to add. Note that the 'run()' method of the task executes, not its 'rollback()' method. To use the 'rollback()' method, add the task via 'Collection::add()' instead.

Return Value

$this

$this rollbackCode(callable $rollbackTask)

Add arbitrary code to execute as a rollback.

Parameters

callable $rollbackTask

Code to execute during rollback processing.

Return Value

$this

$this completion(TaskInterface $completionTask)

Add a completion task to our task collection. A completion task will execute EITHER after all tasks succeed, OR immediatley after any task fails. Completion tasks never cause errors to be returned from Collection::run(), even if they fail.

Parameters

TaskInterface $completionTask

The completion task to add. Note that the 'run()' method of the task executes, just as if the task was added normally.

Return Value

$this

$this completionCode(callable $completionTask)

Add arbitrary code to execute as a completion.

Parameters

callable $completionTask

Code to execute after collection completes

Return Value

$this

$this before(string $name, callable|TaskInterface $task, int|string $nameOfTaskToAdd = self::UNNAMEDTASK)

Add a task before an existing named task.

Parameters

string $name

The name of the task to insert before. The named task MUST exist.

callable|TaskInterface $task

The task to add.

int|string $nameOfTaskToAdd

The name of the task to add. If not provided, will be associated with the named task it was added before.

Return Value

$this

$this after(string $name, callable|TaskInterface $task, int|string $nameOfTaskToAdd = self::UNNAMEDTASK)

Add a task after an existing named task.

Parameters

string $name

The name of the task to insert before. The named task MUST exist.

callable|TaskInterface $task

The task to add.

int|string $nameOfTaskToAdd

The name of the task to add. If not provided, will be associated with the named task it was added after.

Return Value

$this

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

Print a progress message after Collection::run() has executed all of the tasks that were added prior to the point when this method was called. If one of the previous tasks fail, then this message will not be printed.

Parameters

string $text

Message to print.

array $context

Extra context data for use by the logger. Note that the data from the collection state is merged with the provided context.

LogLevel|string $level

The log level to print the information at. Default is NOTICE.

Return Value

$this