CoolCMS API

OperationRunner
in package

FinalYes

Runs one piece of work as one operation for the entry points that have no `internalAction*()`: cron actions ({@see \App\Core\Base\Cron\BasePresenter}), `bin/*` scripts and CLI harnesses.

Transitional: in scoped mode the read clear is off and only the boundaries of a root operation empty the unit of work, so a process that calls the Api managers directly and never begins an operation would keep its identity map for its whole life and find() would keep returning instances loaded before a write done outside of them (raw SQL, another process, a restored snapshot). Wrapping each step in self::run() gives it the same begin/end as an Api action; the mechanism is the one of BasePresenter::operation() (begin and end on OperationScope, participants decide what a store does), the runner only adds the source and the outcome.

Rules for the caller (the same as for an Api action): entities never cross the boundary of a step, only values and IDs; whatever a step needs, it loads inside it. A step started inside a running operation (an Api action through the bridge, or another step) only joins it and clears nothing.

Observation off: the body runs directly, nothing else happens.

Table of Contents

Constants

PRESENTER_CLI  : string = 'cli'

Properties

$operationScope  : OperationScope

Methods

__construct()  : mixed
cli()  : T
Shortcut for `bin/*` scripts and harnesses: one step of a CLI process, presenter `cli`.
resolveOutcome()  : OperationOutcome
{@see Result} or the Api envelope (`success` + `code`): success = succeeded, refusal = rejected, technical {@see ResultCode} = failed; anything else unknown.
run()  : T
Runs `$body` between begin and end of one operation and returns its result unchanged.

Constants

Properties

Methods

cli()

Shortcut for `bin/*` scripts and harnesses: one step of a CLI process, presenter `cli`.

public static cli(Container $container, string $name, callable(): T $body) : T
Parameters
$container : Container
$name : string
$body : callable(): T
Tags
template
Return values
T

resolveOutcome()

{@see Result} or the Api envelope (`success` + `code`): success = succeeded, refusal = rejected, technical {@see ResultCode} = failed; anything else unknown.

public static resolveOutcome(mixed $result) : OperationOutcome
Parameters
$result : mixed
Return values
OperationOutcome

run()

Runs `$body` between begin and end of one operation and returns its result unchanged.

public run(string $source, string $presenter, string $action, callable(): T $body[, callable(Throwable): Array|null $regularExit = null ]) : T

The outcome comes from the result (self::resolveOutcome()). An exception is recorded as failed and rethrown unchanged, unless $regularExit classifies it as a regular end of the work (a cron action leaves with AbortException after it sent its response): then the operation ends with that outcome and the exception still leaves. Like in an Api action, the only exception of its own is OperationContractViolationException (scoped, outside production by default) after a body that did not fail.

Parameters
$source : string
$presenter : string
$action : string
$body : callable(): T
$regularExit : callable(Throwable): Array|null = null

null = the exception is a failure

Tags
template
Return values
T
On this page

Search results