2017-01-21 23:07:20 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Engelsystem\Config;
|
|
|
|
|
2018-01-14 01:45:23 +01:00
|
|
|
use Illuminate\Support\Fluent;
|
|
|
|
|
|
|
|
class Config extends Fluent
|
2017-01-21 23:07:20 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The config values
|
|
|
|
*/
|
2022-12-15 19:50:56 +01:00
|
|
|
protected $attributes = []; // phpcs:ignore
|
2017-01-21 23:07:20 +01:00
|
|
|
|
|
|
|
/**
|
2022-12-14 00:28:34 +01:00
|
|
|
* @param string|array $key
|
2017-01-21 23:07:20 +01:00
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
public function get(mixed $key, mixed $default = null): mixed
|
2017-01-21 23:07:20 +01:00
|
|
|
{
|
|
|
|
if (is_null($key)) {
|
2018-01-14 01:45:23 +01:00
|
|
|
return $this->attributes;
|
2017-01-21 23:07:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->has($key)) {
|
2018-01-14 01:45:23 +01:00
|
|
|
return $this->attributes[$key];
|
2017-01-21 23:07:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string|array $key
|
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
public function set(mixed $key, mixed $value = null): void
|
2017-01-21 23:07:20 +01:00
|
|
|
{
|
|
|
|
if (is_array($key)) {
|
|
|
|
foreach ($key as $configKey => $configValue) {
|
|
|
|
$this->set($configKey, $configValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-14 01:45:23 +01:00
|
|
|
$this->attributes[$key] = $value;
|
2017-01-21 23:07:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $key
|
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
public function has(mixed $key): bool
|
2017-01-21 23:07:20 +01:00
|
|
|
{
|
2018-01-14 01:45:23 +01:00
|
|
|
return $this->offsetExists($key);
|
2017-01-21 23:07:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $key
|
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
public function remove(mixed $key): void
|
2017-01-21 23:07:20 +01:00
|
|
|
{
|
2018-01-14 01:45:23 +01:00
|
|
|
$this->offsetUnset($key);
|
2017-01-21 23:07:20 +01:00
|
|
|
}
|
|
|
|
}
|