OperationScope
in package
Begins and ends operations and tells the registered participants about them.
An operation is one Api action body (internalAction*()), started by
BasePresenter::operation() for both transports (HTTP and bridge). Entry points
without one (cron actions, bin/* scripts, CLI harnesses) begin and end it through OperationRunner
(transitional, until Cron calls the Api).
The scope knows nothing about Doctrine, SQL or cache; stores join through the DI tag
self::PARTICIPANT_TAG.
Contract (observe-only phase):
- a
begin()while an operation runs does not start a new one; it returns a joined frame whoseend()closes nothing and calls no participant; - a frame is ended at most once; a second end, a foreign or cloned frame is logged and ignored, so it can never close the running root;
- ending a root while joined frames are still open closes them too (logged), so no orphan stays on the stack for the next operation;
- nothing thrown by a participant or by logging leaves this class: the result and the primary exception of the operation are never replaced. The one exception is OperationContractViolationException: it is rethrown from end() after every participant ended and the frame was closed (the context is clean for the next operation), and only when the operation did not fail with its own exception; otherwise it is logged and dropped.
Disabled (the default, params.1.operations.observe), operation() calls the body directly and
this class is never asked to begin anything.
Table of Contents
Constants
- LOG_CHANNEL : string = 'operations'
- PARTICIPANT_TAG : string = 'operation.participant'
Properties
- $closed : WeakMap<OperationFrame, true>
- $context : OperationContext
- $enabled : bool
- $open : WeakMap<OperationFrame, bool>
- Open frames issued by this scope: `true` = root, `false` = joined. Weak keys keep the record bounded: a frame nobody holds any more disappears from it.
- $participants : array<int, OperationParticipant>
Methods
- __construct() : mixed
- begin() : OperationFrame
- end() : void
- isEnabled() : bool
- close() : OperationContractViolationException|null
- log() : void
- Lifecycle problems only; the per-operation line is written by the participants.
- markClosed() : void
Constants
LOG_CHANNEL
public
string
LOG_CHANNEL
= 'operations'
PARTICIPANT_TAG
public
string
PARTICIPANT_TAG
= 'operation.participant'
Properties
$closed
private
WeakMap<OperationFrame, true>
$closed
$context read-only
private
OperationContext
$context
$enabled read-only
private
bool
$enabled
$open
Open frames issued by this scope: `true` = root, `false` = joined. Weak keys keep the record bounded: a frame nobody holds any more disappears from it.
private
WeakMap<OperationFrame, bool>
$open
$participants
private
array<int, OperationParticipant>
$participants
= []
Methods
__construct()
public
__construct(bool $enabled, OperationContext $context[, iterable<string|int, mixed> $participants = [] ]) : mixed
Parameters
- $enabled : bool
- $context : OperationContext
- $participants : iterable<string|int, mixed> = []
-
services tagged self::PARTICIPANT_TAG
begin()
public
begin(string $source, string $presenter, string $action) : OperationFrame
Parameters
- $source : string
- $presenter : string
- $action : string
Return values
OperationFrameend()
public
end(OperationFrame $frame, OperationOutcome $outcome[, Throwable|null $primary = null ]) : void
Parameters
- $frame : OperationFrame
- $outcome : OperationOutcome
- $primary : Throwable|null = null
Tags
isEnabled()
public
isEnabled() : bool
Return values
boolclose()
private
close(OperationFrame $frame, OperationOutcome $outcome, Throwable|null $primary) : OperationContractViolationException|null
Parameters
- $frame : OperationFrame
- $outcome : OperationOutcome
- $primary : Throwable|null
Return values
OperationContractViolationException|nulllog()
Lifecycle problems only; the per-operation line is written by the participants.
private
log(string $problem, OperationFrame $frame, string|null $detail) : void
Parameters
- $problem : string
- $frame : OperationFrame
- $detail : string|null
markClosed()
private
markClosed(OperationFrame $frame) : void
Parameters
- $frame : OperationFrame