Configurator
Travis |
Coverage |
Stable Version |
Downloads |
PHP |
License |
|
|
|
|
|
|
A simple configuration class without dependencies that use the Fluent pattern., (*1)
Requirement
, (*2)
Installation
composer require xety/configurator
Usage
The Configurator
class is an abstract class, so you just need to extends
it:, (*3)
<?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 :, (*4)
<?php
class MyClass extends Configurator
{
protected $defaultConfig = [
'key' => 'value',
//etc
];
public function __construct()
{
$this->setConfig($defaultConfig);
}
}
Docs
Methods
Configurator::setConfig
public setConfig (array $values)
Description, (*5)
Set the values to the options array.
This function will replace all the configuration options., (*6)
Parameters, (*7)
-
(array) $values
: The values to push into the config.
Return Values, (*8)
\Xety\Configurator\Configurator::class
, (*9)
Configurator::getConfig
public getConfig (void)
Description, (*10)
Get all the options with their values., (*11)
Parameters, (*12)
This function has no parameters.
, (*13)
Return Values, (*14)
array
, (*15)
Configurator::flushConfig
public flushConfig (string ...$filter)
Description, (*16)
Flush a list of options from the options array., (*17)
Usage:, (*18)
$this->flushConfig('key1', 'key2', 'key3');
Parameters, (*19)
-
(string) ...$filter
: All the options to remove from the config.
Return Values, (*20)
\Xety\Configurator\Configurator::class
, (*21)
Configurator::mergeConfig
public mergeConfig (array $values, bool $invert = false)
Description, (*22)
Merge the values to the options array., (*23)
Parameters, (*24)
-
(array) $values
: The values to merge in the config.
-
(bool) $invert
: Invert the merge by merging the actual config into the values.
Return Values, (*25)
\Xety\Configurator\Configurator::class
, (*26)
Configurator::clearConfig
public clearConfig (void)
Description, (*27)
Clear all options stored., (*28)
Parameters, (*29)
This function has no parameters.
, (*30)
Return Values, (*31)
\Xety\Configurator\Configurator::class
, (*32)
Configurator::setOption
public setOption (string $name, mixed $value)
Description, (*33)
Set a value to the given option., (*34)
Usage:, (*35)
$this->setOption('key', 'value');
$this->setOption('key', ['key2' => ['value2']]);
Parameters, (*36)
-
(string) $name
: The option name.
-
(mixed) $value
: The option value.
Return Values, (*37)
\Xety\Configurator\Configurator::class
, (*38)
Configurator::getOption
public getOption (string $name)
Description, (*39)
Get an option value., (*40)
Usage:, (*41)
$this->getOption('key');
Parameters, (*42)
-
(string) $name
: The option name to to get.
Return Values, (*43)
mixed
, (*44)
Configurator::hasOption
public hasOption (string $name)
Description, (*45)
Check if the option exist., (*46)
Parameters, (*47)
-
(string) $name
: The option name to check.
Return Values, (*48)
bool
, (*49)
Configurator::flushOption
public flushOption (string $name)
Description, (*50)
Flush an option., (*51)
Parameters, (*52)
-
(string) $name
: The name of the option to flush.
Return Values, (*53)
\Xety\Configurator\Configurator::class
, (*54)
Configurator::pushOption
public pushOption (string $name, array $args)
Description, (*55)
Push the listed args to the named option., (*56)
Usage:, (*57)
$this->pushOption('key', ['key1' => 'value1'], ['key2' => ['value2' => 'value3']]);
Result:, (*58)
'key' => [
'key1' => 'value1',
'key2' => [
'value2' => 'value3'
]
]
Parameters, (*59)
-
(string) $name
: The name of the option.
-
(array) $args
: A list of values to push into the option key.
Return Values, (*60)
\Xety\Configurator\Configurator::class
, (*61)
Configurator::consumeOption
public consumeOption (string $name)
Description, (*62)
Read then flush an option.
Exemple:, (*63)
Config:, (*64)
$config = [
'key1' => 'value1'
];
Usage:, (*65)
$result = $this->consumeOption('key1');
Result:, (*66)
echo $result; // value1
var_dump($config); // []
Parameters, (*67)
-
(string) $name
: The name of the option to read then flush.
Return Values, (*68)
mixed
, (*69)
Configurator::transientOption
public transientOption (string $name, mixed $value)
Description, (*70)
Adds a transient configuration key/value., (*71)
Usage:, (*72)
// 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, (*73)
-
(string) $name
: The name of the option.
-
(mixed) $value
: The value to set.
Return Values, (*74)
\Xety\Configurator\Configurator::class
, (*75)
Contribute
If you want to contribute, please follow this guide., (*76)