php-cooper

EnvReference
in package

FinalYes

One `${NAME}` written as a value, as the `envValue` load option sees it (see `Cooper`): the name it reads and everything written around it.

It exists for a host that resolves the environment later than the load -- a framework compiling configuration into a cache, which must keep ${DB_PASSWORD} a runtime placeholder rather than bake the value the build machine happened to have. The option sees every ${...} resolution would read a value from, and nothing else: a ${?NAME} guard, a ${NAME} in an import path or an interpolated key decide the document's shape, and are always read at load time.

$tag is set when the reference is written directly as a tag's argument (!int(${PORT})): the option answers for the tagged value as a whole, so a placeholder need not survive a tag that cannot read it. A tag around anything else -- a string holding a reference (!int("${PORT}")), a variable -- is applied to what the option gave back, as to any other value.

Table of Contents

Constants

DEFAULT  : mixed = 'default'
`${NAME:value}` -- the value when `NAME` is unset or empty.
REQUIRED  : mixed = 'required'
`${NAME:?"message"}` -- an error saying the message when `NAME` is unset or empty.
SUBSTITUTE  : mixed = 'substitute'
`${NAME:+value}` -- the value when `NAME` is set and not empty.

Properties

$filters  : array<string|int, mixed>
$index  : int|null
$list  : bool
$name  : string
$suffix  : string|null
$tag  : string|null
$suffixValue  : Closure

Methods

__construct()  : mixed
suffixValue()  : mixed
The suffix's value, resolved as any other value is -- the default, the substitute, or the required-message -- or `null` without one.

Constants

DEFAULT

`${NAME:value}` -- the value when `NAME` is unset or empty.

public mixed DEFAULT = 'default'

REQUIRED

`${NAME:?"message"}` -- an error saying the message when `NAME` is unset or empty.

public mixed REQUIRED = 'required'

SUBSTITUTE

`${NAME:+value}` -- the value when `NAME` is set and not empty.

public mixed SUBSTITUTE = 'substitute'

Properties

$filters read-only

public array<string|int, mixed> $filters

Methods

__construct()

public __construct(string $name, bool $list, int|null $index, string|null $suffix, array<int, string> $filters, string|null $tag, callable(): mixed $suffixValue) : mixed
Parameters
$name : string

the variable, a built name (${"TOKEN_@{id}"}) already resolved

$list : bool

the ${NAME[]} form: the value split into a list

$index : int|null

the ${NAME[i]} form's index

$suffix : string|null

DEFAULT, SUBSTITUTE, REQUIRED, or null for none

$filters : array<int, string>

the | name filters, in order

$tag : string|null

the tag written directly around the reference, without its !

$suffixValue : callable(): mixed

resolves the suffix's value

suffixValue()

The suffix's value, resolved as any other value is -- the default, the substitute, or the required-message -- or `null` without one.

public suffixValue() : mixed

Resolved only when asked for: an unused default that references something undefined is no error, as it is none in a normal load.

Tags
throws
CooperError

(stage resolve) when the value does not resolve

Return values
mixed —

the resolved value

On this page

Search results