| Travis | Coverage | Stable Version | Downloads | PHP | License |
|---|---|---|---|---|---|
A simple configuration class without dependencies that use the Fluent pattern.
composer require xety/configuratorThe Configurator class is an abstract class, so you just need to extends it:
<?php
namespace App;
use Xety\Configurator\Configurator;
class MyClass extends Configurator
{
}If you want to setup a default configuration for your class, just do the following :
<?php
class MyClass extends Configurator
{
protected $defaultConfig = [
'key' => 'value',
//etc
];
public function __construct()
{
$this->setConfig($defaultConfig);
}
}| Name | Description |
|---|---|
| setConfig | Set the values to the options array. |
| getConfig | Get all the options with their values. |
| flushConfig | Flush a list of options from the config array. |
| mergeConfig | Merge the values to the options array. |
| clearConfig | Clear all options stored. |
| setOption | Set a value to the given option. |
| getOption | Get an option value. |
| hasOption | Check if the option exist. |
| flushOption | Flush an option. |
| pushOption | Push the listed args to the named option. |
| consumeOption | Read then flush an option. |
| transientOption | Adds a transient configuration key/value. |
public setConfig (array $values)Description
Set the values to the options array. This function will replace all the configuration options.
Parameters
(array) $values: The values to push into the config.
Return Values
\Xety\Configurator\Configurator::class
public getConfig (void)Description
Get all the options with their values.
Parameters
This function has no parameters.
Return Values
array
public flushConfig (string ...$filter)Description
Flush a list of options from the options array.
Usage:
$this->flushConfig('key1', 'key2', 'key3');Parameters
(string) ...$filter: All the options to remove from the config.
Return Values
\Xety\Configurator\Configurator::class
public mergeConfig (array $values, bool $invert = false)Description
Merge the values to the options array.
Parameters
(array) $values: The values to merge in the config.(bool) $invert: Invert the merge by merging the actual config into the values.
Return Values
\Xety\Configurator\Configurator::class
public clearConfig (void)Description
Clear all options stored.
Parameters
This function has no parameters.
Return Values
\Xety\Configurator\Configurator::class
public setOption (string $name, mixed $value)Description
Set a value to the given option.
Usage:
$this->setOption('key', 'value');
$this->setOption('key', ['key2' => ['value2']]);Parameters
(string) $name: The option name.(mixed) $value: The option value.
Return Values
\Xety\Configurator\Configurator::class
public getOption (string $name)Description
Get an option value.
Usage:
$this->getOption('key');Parameters
(string) $name: The option name to to get.
Return Values
mixed
public hasOption (string $name)Description
Check if the option exist.
Parameters
(string) $name: The option name to check.
Return Values
bool
public flushOption (string $name)Description
Flush an option.
Parameters
(string) $name: The name of the option to flush.
Return Values
\Xety\Configurator\Configurator::class
public pushOption (string $name, array $args)Description
Push the listed args to the named option.
Usage:
$this->pushOption('key', ['key1' => 'value1'], ['key2' => ['value2' => 'value3']]);Result:
'key' => [
'key1' => 'value1',
'key2' => [
'value2' => 'value3'
]
]Parameters
(string) $name: The name of the option.(array) $args: A list of values to push into the option key.
Return Values
\Xety\Configurator\Configurator::class
public consumeOption (string $name)Description
Read then flush an option. Exemple:
Config:
$config = [
'key1' => 'value1'
];Usage:
$result = $this->consumeOption('key1');Result:
echo $result; // value1
var_dump($config); // []Parameters
(string) $name: The name of the option to read then flush.
Return Values
mixed
public transientOption (string $name, mixed $value)Description
Adds a transient configuration key/value.
Usage:
// Will update the value of the key `key` if it exist,
// or it will create it with the value `value`.
$this->transientOption('key', 'value');Parameters
(string) $name: The name of the option.(mixed) $value: The value to set.
Return Values
\Xety\Configurator\Configurator::class
If you want to contribute, please follow this guide.