A general key-value store for user-supplied settings.

A \FeaturePhp\ProductLine\ProductLine and its dependencies can be configured in many ways by the user. The settings class provides a uniform interface for checking, reading and writing individual settings. For a description of the actual settings, see \FeaturePhp\ProductLine\Settings.

package Default

 Methods

Creates settings.

__construct(array $cfg, string $directory = "."

The directory may be used to resolve relative paths in the settings.

Parameters

$cfg

array

a plain settings array

$directory

string

the directory the settings apply to

Creates settings.

fromArray(array $cfg, string $directory = "."
Static

Parameters

$cfg

array

a plain settings array

$directory

string

the directory the settings apply to

Creates settings from a JSON-encoded file.

fromFile(string $fileName) : \FeaturePhp\Settings
Static

Parameters

$fileName

string

Returns

\FeaturePhp\Settings

Creates settings from a JSON-encoded string.

fromString(string $json, string $directory = ".") : \FeaturePhp\Settings
Static

Parameters

$json

string

$directory

string

the directory the settings apply to

Returns

\FeaturePhp\Settings

Returns a setting.

get() : mixed

A setting path can be supplied variadically.

Returns

mixed

Returns the settings' directory.

getDirectory() : string

Returns

string

Returns a setting in a plain settings array.

getIn(array $cfg) : mixed

A setting path can be supplied variadically.

Parameters

$cfg

array

Returns

mixed

Creates an instance of a class from a plain settings array.

getInstance(string|array|boolean $object, string $klass) : \FeaturePhp\$class

If a string is given, the class is instantiated from a file. If an array("data" => ...) is given, the class is instantiated from a string. If another array is given, the class is instantiated from that array. If true is given, the class is instantiated from an empty array.

Parameters

$object

stringarrayboolean

$klass

string

Returns

\FeaturePhp\$class

Returns an optional setting, defaulting to a value.

getOptional(mixed $defaultValue) : mixed

A setting path can be supplied variadically.

Parameters

$defaultValue

mixed

Returns

mixed

Returns a path in the context of the settings' directory.

getPath(string $path) : string

Parameters

$path

string

Returns

string

Returns a setting if a predicate is satisfied.

getWith(string $key, callable $predicate) : mixed

Throws \FeaturePhp\InvalidSettingsException if the predicate fails.

Parameters

$key

string

$predicate

callable

Returns

mixed

Creates empty settings in the context of a directory.

inDirectory(string $directory) 
Static

Parameters

$directory

string

the directory the settings apply to

Returns whether a plain settings array has a key.

has(string $key, array $cfg = null) : boolean

If no settings array is given, the internal settings array is assumed.

Parameters

$key

string

$cfg

array

Returns

boolean

Sets a setting.

set(string $key, mixed $value) 

A setting path can be supplied variadically.

Parameters

$key

string

$value

mixed

Sets a setting if it is not already set.

setOptional(string $key, mixed $value) 

Parameters

$key

string

$value

mixed

Returns a setting in a plain settings array.

_get(array $cfg) : mixed

A setting path can be supplied variadically.

Parameters

$cfg

array

Returns

mixed

Sets a setting in a plain settings array.

_set(array $cfg, array $args) 

Parameters

$cfg

array

$args

array

a setting path followed by the setting's new value

 Properties

 

the internal plain settings array

$cfg : array

Default