CoolCMS API

OperationScope
in package

FinalYes

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 whose end() 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

PARTICIPANT_TAG

public string PARTICIPANT_TAG = 'operation.participant'

Properties

$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

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

log()

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
On this page

Search results