-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptions.php
More file actions
100 lines (89 loc) · 1.81 KB
/
Copy pathOptions.php
File metadata and controls
100 lines (89 loc) · 1.81 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
namespace Irmmr\RTLCss;
/**
* class Options
*
* @package Irmmr\RTLCss
* options handler
*/
class Options
{
/**
* default options
* @var array
*/
protected array $def_options = [];
/**
* all options holder
* @var array
*/
protected array $options = [];
/**
* class constructor
*
* @param array $def_options
*/
public function __construct(array $def_options = [])
{
$this->options = $this->def_options = $def_options;
}
/**
* set options (merge)
*
* @array $options
*/
public function set(array $options): void
{
$this->options = array_merge($this->options, $options);
}
/**
* reset options
*
* @array $options
*/
public function reset(): void
{
$this->options = $this->def_options;
}
/**
* get options
*
* @param string|null $key
* @param null $def
* @return mixed
*/
public function get(?string $key = null, $def = null)
{
if (!is_null($key)) {
return $this->has($key) ? $this->options[$key] : $def;
}
return $this->options;
}
/**
* check options
*
* @param string|null $key
* @return bool
*/
public function has(?string $key = null): bool
{
if (is_null($key)) {
return !empty($this->options);
}
return array_key_exists($key, $this->options);
}
/**
* create options if not exists
*
* @param array $options
* @param mixed $value
*/
public function create(array $options, $value): void
{
foreach ($options as $option) {
if (!$this->has($option)) {
$this->set([ $option => $value ]);
}
}
}
}