class Options implements ArrayAccess, Iterator, Countable

Container for resolving inter-dependent options.

Methods

set(string $option, mixed $value)

Sets the value of a given option.

setNormalizer(string $option, Closure $normalizer)

Sets the normalizer for a given option.

replace(array $options)

Replaces the contents of the container with the given options.

overload(string $option, mixed $value)

Overloads the value of a given option.

mixed
get(string $option)

Returns the value of the given option.

Boolean
has(string $option)

Returns whether the given option exists.

remove(string $option)

Removes the option with the given name.

clear()

Removes all options.

array
all()

Returns the values of all options.

Boolean
offsetExists(string $option)

Equivalent to {@link has()}.

mixed
offsetGet(string $option)

Equivalent to {@link get()}.

offsetSet(string $option, mixed $value)

Equivalent to {@link set()}.

offsetUnset(string $option)

Equivalent to {@link remove()}.

current()

{@inheritdoc}

next()

{@inheritdoc}

key()

{@inheritdoc}

valid()

{@inheritdoc}

rewind()

{@inheritdoc}

count()

{@inheritdoc}

Details

at line line 80
set(string $option, mixed $value)

Sets the value of a given option.

You can set lazy options by passing a closure with the following signature:

function (Options $options)

This closure will be evaluated once the option is read using {@link get()}. The closure has access to the resolved values of other options through the passed {@link Options} instance.

Parameters

string $option The name of the option.
mixed $value The value of the option.

Exceptions

OptionDefinitionException If options have already been read. Once options are read, the container becomes immutable.

at line line 117
setNormalizer(string $option, Closure $normalizer)

Sets the normalizer for a given option.

Normalizers should be closures with the following signature:

function (Options $options, $value)

This closure will be evaluated once the option is read using {@link get()}. The closure has access to the resolved values of other options through the passed {@link Options} instance.

Parameters

string $option The name of the option.
Closure $normalizer The normalizer.

Exceptions

OptionDefinitionException If options have already been read. Once options are read, the container becomes immutable.

at line line 138
replace(array $options)

Replaces the contents of the container with the given options.

This method is a shortcut for {@link clear()} with subsequent calls to {@link set()}.

Parameters

array $options The options to set.

Exceptions

OptionDefinitionException If options have already been read. Once options are read, the container becomes immutable.

at line line 174
overload(string $option, mixed $value)

Overloads the value of a given option.

Contrary to {@link set()}, this method keeps the previous default value of the option so that you can access it if you pass a closure. Passed closures should have the following signature:

function (Options $options, $value)

The second parameter passed to the closure is the current default value of the option.

Parameters

string $option The option name.
mixed $value The option value.

Exceptions

OptionDefinitionException If options have already been read. Once options are read, the container becomes immutable.

at line line 223
mixed get(string $option)

Returns the value of the given option.

If the option was a lazy option, it is evaluated now.

Parameters

string $option The option name.

Return Value

mixed The option value.

Exceptions

OutOfBoundsException If the option does not exist.
OptionDefinitionException If a cyclic dependency is detected between two lazy options.

at line line 249
Boolean has(string $option)

Returns whether the given option exists.

Parameters

string $option The option name.

Return Value

Boolean Whether the option exists.

at line line 263
remove(string $option)

Removes the option with the given name.

Parameters

string $option The option name.

Exceptions

OptionDefinitionException If options have already been read. Once options are read, the container becomes immutable.

at line line 281
clear()

Removes all options.

Exceptions

OptionDefinitionException If options have already been read. Once options are read, the container becomes immutable.

at line line 299
array all()

Returns the values of all options.

Lazy options are evaluated at this point.

Return Value

array The option values.

at line line 331
Boolean offsetExists(string $option)

Equivalent to {@link has()}.

Parameters

string $option The option name.

Return Value

Boolean Whether the option exists.

See also

\ArrayAccess::offsetExists()

at line line 349
mixed offsetGet(string $option)

Equivalent to {@link get()}.

Parameters

string $option The option name.

Return Value

mixed The option value.

Exceptions

OutOfBoundsException If the option does not exist.
OptionDefinitionException If a cyclic dependency is detected between two lazy options.

See also

\ArrayAccess::offsetGet()

at line line 367
offsetSet(string $option, mixed $value)

Equivalent to {@link set()}.

Parameters

string $option The name of the option.
mixed $value The value of the option. May be a closure with a signature as defined in DefaultOptions::add().

Exceptions

OptionDefinitionException If options have already been read. Once options are read, the container becomes immutable.

See also

\ArrayAccess::offsetSet()

at line line 383
offsetUnset(string $option)

Equivalent to {@link remove()}.

Parameters

string $option The option name.

Exceptions

OptionDefinitionException If options have already been read. Once options are read, the container becomes immutable.

See also

\ArrayAccess::offsetUnset()

at line line 391
current()

{@inheritdoc}

at line line 399
next()

{@inheritdoc}

at line line 407
key()

{@inheritdoc}

at line line 415
valid()

{@inheritdoc}

at line line 423
rewind()

{@inheritdoc}

at line line 431
count()

{@inheritdoc}