\Drupal\strata\Capture KeyValueCaptureFactory

Hands out key-value stores that record what is written to them.

The keyvalue service is a factory, so the factory is what gets decorated and each store it produces is wrapped on the way out. Stores are cached per collection here as well as in the inner factory, so a collection asked for twice returns the same wrapper and not two.

Strata's own collections are handed through unwrapped. Recording the journal's own bookkeeping in the journal is a feedback loop rather than a backup.

So is the state collection, for a different reason. Core's state service is State(@keyvalue, ...) and its constructor asks this factory for the collection called state, so a wrapped store there means every state write is recorded twice - once as state by StateCapture, and again as keyvalue under the subject state:<key>.

The expirable factory is deliberately NOT decorated. An expirable value is a cache with a deadline; capturing one would record something whose correct future state is "gone", and restoring it would put back an entry the site had already finished with.

Summary

Methods
Properties
Constants
__construct
get
No public properties found
OWN_PREFIX
CAPTURED_ELSEWHERE
No protected methods found
No protected properties found
No protected constants found
isCapturedElsewhere
stores
inner
recorder
No private constants found

Constant

OWN_PREFIX

OWN_PREFIX = 'strata'

Collection prefix this module owns, never captured.

CAPTURED_ELSEWHERE

CAPTURED_ELSEWHERE = ['state'] : array&lt;int, string&gt;

Collections another decorator already records, so wrapping them would double-count.

Properties

$stores

$stores : array

Wrapped stores, keyed by collection.

Type

array<string, KeyValueStoreInterface> —

$inner

$inner : \Drupal\Core\KeyValueStore\KeyValueFactoryInterface

Type

KeyValueFactoryInterface

$recorder

$recorder : \Drupal\strata\Capture\KeyRecorder|\Closure

Type

KeyRecorder|Closure

Methods

__construct()

__construct(\Drupal\Core\KeyValueStore\KeyValueFactoryInterface  $inner, \Drupal\strata\Capture\KeyRecorder|\Closure  $recorder) : mixed

Constructs the factory.

Parameters

\Drupal\Core\KeyValueStore\KeyValueFactoryInterface $inner

The factory being wrapped.

\Drupal\strata\Capture\KeyRecorder|\Closure $recorder

Journals each write the stores make, or a closure returning one.

A closure is what a site gets, and it is not an optimisation.* Core's DevelopmentSettingsPass calls $container->get('keyvalue')->get('development_settings') while the container is still being compiled, so everything keyvalue depends on has to be constructible at that moment. A recorder is not: it needs the journal and a logger channel, and both resolve through definitions Symfony refuses to build during compilation. Passing the recorder directly makes every container rebuild on a real site fail.

Returns

mixed —

get()

get(mixed  $collection) : mixed

{@inheritdoc}

Parameters

mixed $collection

Returns

mixed —

isCapturedElsewhere()

isCapturedElsewhere(string  $collection) : bool

Whether a collection is already recorded by a decorator of its own.

Parameters

string $collection

The collection name.

Returns

bool —

TRUE when wrapping it here would record the same write twice.