Skip to content

RecordingEnvironmentReader

A decorating environment reader: wraps a real inner EnvironmentReaderInterface and appends one EffectKind::Env entry per get() call to an injected EffectLedger, returning the real value completely untouched to the caller.

Fingerprint is the bare variable name — unlike RecordingCache’s operation-scoped fingerprint, there is only one operation here (get(); environment variables are never written through this interface), so there is no cross-operation collision to guard against.

getenv()’s own contract already distinguishes “unset” (false) from any string value, including an empty one, so no extra hit/miss sentinel is needed the way RecordingCache::get() needed one for PSR-16’s null-vs-miss ambiguity: the recorded result is simply the exact string|false the inner reader returned.

A real-reader exception is never swallowed: no effect is recorded for a failed call, and the exception propagates exactly as it would through the undecorated reader, matching every other recorder in this package.

final class RecordingEnvironmentReader implements EnvironmentReaderInterface

ImplementsEnvironmentReaderInterface
SourceEnv/RecordingEnvironmentReader.php

public function __construct(EnvironmentReaderInterface $reader, EffectLedger $ledger, ClockInterface $clock = new SystemClock(…)): mixed

ParameterTypeDescription
$readerEnvironmentReaderInterface
$ledgerEffectLedger
$clockClockInterface

Returns mixed

MethodDescription
[`get(string $name): stringfalse`](#get)

public function get(string $name): string|false

The value of environment variable $name, or false when it is unset.

ParameterTypeDescription
$namestring

Returns string``|``false