Class Config
Provides synthesized low-level configurations.
-
ICanBoogie\Config
implements
ArrayAccess
Methods summary
public
__construct( array $paths
, array $synthesizers
= [], ICanBoogie\Storage\Storage $cache
= null )
public
offsetSet( $offset
, $value
)
Throws
OffsetNotWritable
in attempt to set a configuration.
Inheritdoc
Implementation of
ArrayAccess::offsetSet()
public
offsetExists( string $id
)
: boolean
Checks if a config has been synthesized.
Checks if a config has been synthesized.
Parameters
$id
- The identifier of the config.
Returns
boolean
true
if the config has been synthesized, false
otherwise.
Implementation of
ArrayAccess::offsetExists()
public
offsetUnset( $offset
)
Throws
OffsetNotWritable
in attempt to unset an offset.
Inheritdoc
Implementation of
ArrayAccess::offsetUnset()
public
offsetGet( string $id
)
: mixed
Returns the specified synthesized configuration.
Returns the specified synthesized configuration.
Parameters
$id
- The identifier of the config.
Returns
mixed
Throws
InvalidArgumentException
in attempt to obtain an undefined config.
Implementation of
ArrayAccess::offsetGet()
protected
revoke( void )
Revokes the synthesized configs and the cache key.
Revokes the synthesized configs and the cache key.
The method is usually called after the config paths have been modified.
public
add( string|array $path
, integer $weight
= 0 )
Adds a path or several paths to the config.
Adds a path or several paths to the config.
Paths are sorted according to their weight. The order in which they were defined is
preserved for paths with the same weight.
<?php
$config->add('/path/to/config', 10);
$config->add([
'/path1/to/config' => 10,
'/path2/to/config' => 10,
'/path2/to/config' => -10
]);
Parameters
$path
$weight
- Weight of the path. The argument is discarded if
$path
is an array.
Throws
InvalidArgumentException
if the path is empty.
public
get_fragments( string $name
)
: array
Returns the fragments of a configuration.
Returns the fragments of a configuration.
Parameters
$name
- Name of the configuration.
Returns
array
Where key is the pathname to the fragment file and value the value
returned when the file was required.
public
synthesize( string $name
, string|array $synthesizer
, null|string $from
= null )
: mixed
Synthesize a configuration.
Synthesize a configuration.
Parameters
$name
- Name of the configuration to synthesize.
$synthesizer
- Callback for the synthesis.
$from
If the configuration is a derivative $from is the name
of the source configuration.
Returns
mixed
Properties summary
protected
$paths
: array
An array of key/value where key is a path to a config directory and value is its weight.
The array is sorted according to the weight of the paths.
An array of key/value where key is a path to a config directory and value is its weight.
The array is sorted according to the weight of the paths.
[]
protected
$synthesizers
: array
Callbacks to synthesize the configurations.
Callbacks to synthesize the configurations.
[]
protected
$synthesized
: array
Synthesized configurations.
Synthesized configurations.
[]
public
$cache
: ICanBoogie\Storage\Storage
A cache to store and retrieve the synthesized configurations.
A cache to store and retrieve the synthesized configurations.