Deployee /
config
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Deployee\Components\Config; |
||
| 4 | |||
| 5 | |||
| 6 | class Config implements ConfigInterface |
||
| 7 | { |
||
| 8 | /** |
||
| 9 | * @var array|\ArrayAccess |
||
| 10 | */ |
||
| 11 | private $params; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Config constructor. |
||
| 15 | * @param array|\ArrayAccess|null $params |
||
| 16 | */ |
||
| 17 | public function __construct($params = null) |
||
| 18 | { |
||
| 19 | if($params !== null){ |
||
| 20 | $this->setParams($params); |
||
| 21 | } |
||
| 22 | } |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @param array|\ArrayAccess $params |
||
| 26 | */ |
||
| 27 | public function setParams($params) |
||
| 28 | { |
||
| 29 | if(!is_array($params) |
||
| 30 | && !$params instanceof \ArrayAccess){ |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 31 | throw new \InvalidArgumentException("Params must be array or implement \\ArrayAcess interface"); |
||
| 32 | } |
||
| 33 | |||
| 34 | $this->params = $params; |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @param string $name |
||
| 39 | * @param mixed $default |
||
| 40 | * @return mixed |
||
| 41 | */ |
||
| 42 | public function get($name, $default = null) |
||
| 43 | { |
||
| 44 | return $this->params[$name] ?? $default; |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @param string $name |
||
| 49 | * @param mixed $value |
||
| 50 | */ |
||
| 51 | public function set(string $name, $value) |
||
| 52 | { |
||
| 53 | $this->params[$name] = $value; |
||
| 54 | } |
||
| 55 | |||
| 56 | |||
| 57 | } |