\Drupal\strata\Capture KeyRecorder

Records a change to one key in a key-addressed store.

State and the key-value collections are the same shape - a key, a serializable value, set and delete - and they have no events, so capture is a decorator around each store. This is the part both decorators share, kept separate so neither has to know about journals, actors or timestamps.

PayloadCodec decides how a value is encoded, because the replayer has to decode it the same way.

Summary

Methods
Properties
Constants
__construct
covers
written
deleted
renamed
No public properties found
No public constants found
No protected methods found
No protected properties found
No protected constants found
record
actor
now
journal
scope
currentUser
logger
requestId
No private constants found

Properties

$journal

$journal : \Drupal\strata\Journal\JournalInterface

Type

JournalInterface

$scope

$scope : \Drupal\strata\Capture\CaptureScope

Type

CaptureScope

$currentUser

$currentUser : \Drupal\Core\Session\AccountProxyInterface

Type

AccountProxyInterface

$logger

$logger : \Psr\Log\LoggerInterface

Type

LoggerInterface

$requestId

$requestId : string

Type

string

Methods

__construct()

__construct(\Drupal\strata\Journal\JournalInterface  $journal, \Drupal\strata\Capture\CaptureScope  $scope, \Drupal\Core\Session\AccountProxyInterface  $currentUser, \Psr\Log\LoggerInterface  $logger, string  $requestId = '') : mixed

Constructs a recorder.

Parameters

\Drupal\strata\Journal\JournalInterface $journal

Where operations are appended.

\Drupal\strata\Capture\CaptureScope $scope

Decides whether the realm is captured.

\Drupal\Core\Session\AccountProxyInterface $currentUser

Attributes an operation to whoever caused it.

\Psr\Log\LoggerInterface $logger

Records a capture that failed.

string $requestId

Groups every operation captured in one request.

Returns

mixed —

covers()

covers(\Drupal\strata\Journal\Realm  $realm) : bool

Whether a realm is captured at all.

Checked by a decorator before it reads the old value, since reading it is the only cost the decorator adds and there is no point paying it for a realm nobody captures.

Parameters

\Drupal\strata\Journal\Realm $realm

The realm.

Returns

bool —

TRUE when operations in this realm are recorded.

written()

written(\Drupal\strata\Journal\Realm  $realm, string  $subject, mixed  $value, bool  $existed) : void

Records a value being written.

Parameters

\Drupal\strata\Journal\Realm $realm

Realm::STATE or Realm::KEY_VALUE.

string $subject

The subject key: a state key, or collection:key for a key-value pair.

mixed $value

The value written.

bool $existed

Whether the key held a value before, which decides create against update.

Returns

void —

deleted()

deleted(\Drupal\strata\Journal\Realm  $realm, string  $subject) : void

Records a key being removed.

Parameters

\Drupal\strata\Journal\Realm $realm

Realm::STATE or Realm::KEY_VALUE.

string $subject

The subject key.

Returns

void —

renamed()

renamed(\Drupal\strata\Journal\Realm  $realm, string  $from, string  $to, mixed  $value) : void

Records a key being renamed.

Recorded as a write of the new key plus a delete of the old, so a restore walking forward produces one key rather than two.

Parameters

\Drupal\strata\Journal\Realm $realm

Realm::KEY_VALUE, the only store that renames.

string $from

The subject key it moved from.

string $to

The subject key it moved to.

mixed $value

The value that moved.

Returns

void —

record()

record(\Drupal\strata\Journal\Realm  $realm, string  $subject, \Drupal\strata\Journal\Verb  $verb, mixed  $value, bool  $hasValue, string|null  $from = null) : void

Appends one operation.

The value is encoded inside the try, not passed in already encoded, because PayloadCodec refuses a value JSON cannot represent and a refusal thrown from the argument list would escape past this catch and break the write that caused the capture.

Parameters

\Drupal\strata\Journal\Realm $realm

The realm.

string $subject

The subject key.

\Drupal\strata\Journal\Verb $verb

What happened.

mixed $value

The value written, ignored when $hasValue is FALSE.

bool $hasValue

FALSE for a delete, which carries no payload.

string|null $from

The key it was renamed from, or NULL.

Returns

void —

actor()

actor() : int|null

The user an operation is attributed to.

Returns

int|null —

A Drupal user id, or NULL for unattended work.

now()

now() : int

The current time in unix microseconds.

Returns

int —

Microseconds since the epoch.