Skip to content
docsv0.8.0

Secret

An opaque wrapper around a raw secret (a database/redis password, an API key, …) plus its non-secret {@see self::$name}. Mirrors the family secret-bearing idiom (see Milpa\Auth\Credential): the value is a `private readonly` property marked `#[\SensitiveParameter]` (redacted from stack-trace argument dumps), {@see self::__debugInfo()} redacts it, and {@see self::__serialize()} and {@see self::__clone()} refuse outright. There is deliberately NO `__toString()`. The one deliberate exit is {@see self::value()}, called only at an audited plaintext boundary. Secret-bearing objects redact the common logging paths. `var_export`/`(array)` remain able to reach the private value — they are prohibited introspection/persistence antipatterns, not defended here. `$name` is a stable, non-secret identifier (e.g. 'MYSQL_PASSWORD'). It MUST NEVER contain the value, a fragment of it, a private host, or any sensitive material.

Secret::__construct()

public function __construct(string $name, string $value):

Parameters

Parameters of __construct()
NameTypeDescription
$namestring
$valuestring

Secret::required()

public static function required(string $name, ?string $raw): self

A required secret. Absence — null OR blank-after-trim — fails closed. The stored value is NEVER trimmed; `trim()` is used only to detect absence, so a password with intentional leading/trailing spaces survives verbatim.

Parameters

Parameters of required()
NameTypeDescription
$namestring
$raw?string

Secret::optional()

public static function optional(string $name, ?string $raw): ?self

An optional secret (e.g. a Redis password on an unauthenticated instance). Absent → null.

Parameters

Parameters of optional()
NameTypeDescription
$namestring
$raw?string

Secret::value()

public function value(): string

Secret::name()

public function name(): string

Secret::__debugInfo()

public function __debugInfo(): array

Secret::__serialize()

public function __serialize(): array

Throws

\LogicException always

Secret::__clone()

public function __clone(): void