CooperSecret
in package
implements
Stringable, JsonSerializable
Wraps a secret value (CASC.md ยง4.3's `*key`-prefixed keys) in the result `Cooper::loadFile()`/`Cooper::loadString()` return, so it never leaks by accident: string conversion, `json_encode()`, `var_dump()`, and `print_r()` all redact regardless of the wrapped value. Reach the real value deliberately with `reveal()` -- the wrapping is only ever a display-time concern, never a barrier to the developer's own use of the value.
var_export() and serialize() are not redacted: neither has a hook
a class can intercept without also breaking deliberate use.
Partial redaction
A secret embedded inside a larger interpolated string
("postgres://user:%{database.password}@host") redacts only the
embedded portion: (string) $secret renders
"postgres://user:[~~REDACTED~~]@host", and several secrets in one
string each redact independently. $redacted carries that
precomputed display text; null (an ordinary whole-value secret)
falls back to the blanket [~~REDACTED~~] marker. reveal() always
returns the real, fully unmasked value.
Table of Contents
Interfaces
- Stringable
- JsonSerializable
Constants
- MARKER : mixed = '[~~REDACTED~~]'
- The blanket marker a whole-value secret displays as.
Properties
Methods
- __construct() : mixed
- __debugInfo() : array{redacted: string}
- What `var_dump()`/`print_r()` show: the redacted text only.
- __toString() : string
- The redacted display text -- never the real value.
- jsonSerialize() : string
- Encodes as the redacted display text, never the real value.
- reveal() : mixed
- Unwraps the secret, returning the real, fully unmasked value.
Constants
MARKER
The blanket marker a whole-value secret displays as.
public
mixed
MARKER
= '[~~REDACTED~~]'
Properties
$redacted read-only
public
string|null
$redacted
= null
$value read-only
private
mixed
$value
Methods
__construct()
public
__construct(mixed $value[, string|null $redacted = null ]) : mixed
Parameters
- $value : mixed
-
the real, unmasked value
- $redacted : string|null = null
-
precomputed display text for a partially redacted string, or null for the blanket marker
__debugInfo()
What `var_dump()`/`print_r()` show: the redacted text only.
public
__debugInfo() : array{redacted: string}
Return values
array{redacted: string}__toString()
The redacted display text -- never the real value.
public
__toString() : string
Return values
string —$redacted, or the blanket marker
jsonSerialize()
Encodes as the redacted display text, never the real value.
public
jsonSerialize() : string
Return values
string —the same text as __toString()
reveal()
Unwraps the secret, returning the real, fully unmasked value.
public
reveal() : mixed
Return values
mixed —the real value