-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_option.php
71 lines (56 loc) · 1.86 KB
/
_option.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
declare(strict_types=1);
/*
* This file is part of the QuidPHP package <https://quidphp.com>
* Author: Pierre-Philippe Emond <emondpph@gmail.com>
* License: https://github.com/quidphp/base/blob/master/LICENSE
*/
namespace Quid\Base;
// _option
// trait that grants static methods to deal with static options (within the $config static property)
trait _option
{
// isOption
// retourne vrai si l'option existe
final public static function isOption($key):bool
{
return Arrs::keyExists($key,static::$config['option']);
}
// getOption
// retourne une option du tableau d'option
final public static function getOption($key)
{
return Arrs::get($key,static::$config['option']);
}
// setOption
// ajoute ou change une option dans le tableau d'option
final public static function setOption($key,$value):void
{
Arrs::setRef($key,$value,static::$config['option']);
}
// unsetOption
// enlève une option du tableau d'option
final public static function unsetOption($key):void
{
Arrs::unsetRef($key,static::$config['option']);
}
// option
// retourne le tableau d'options
// possibilité de faire un merge sur la valeur de retour, n'écrit pas dans la variable statique
// par défaut, cette méthode n'écrit pas dans la variable statique (à l'inverse de config)
final public static function option(?array $value=null,bool $write=false):array
{
$return = static::$config['option'];
if($value !== null)
{
if(array_keys($value) !== array_keys(static::$config['option']))
$return = array_replace_recursive(static::$config['option'],$value);
else
$return = $value;
if($write === true)
static::$config['option'] = $return;
}
return $return;
}
}
?>