1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
namespace AbterPhp\Framework\Config; |
7
|
|
|
|
8
|
|
|
use Opulence\Framework\Configuration\Config as OpulenceConfig; |
9
|
|
|
|
10
|
|
|
class Config extends OpulenceConfig |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Gets a setting, but throws an exception if it's empty |
15
|
|
|
* |
16
|
|
|
* @param string $category The category of setting to get |
17
|
|
|
* @param string $setting The name of the setting to get |
18
|
|
|
* @param mixed $default The default value if one does not exist |
19
|
|
|
* |
20
|
|
|
* @return string|int|float|bool The value of the setting |
21
|
|
|
*/ |
22
|
|
|
public static function mustGet(string $category, string $setting, $default = null) |
23
|
|
|
{ |
24
|
|
|
$value = parent::get($category, $setting, $default); |
25
|
|
|
|
26
|
|
|
if ($value === null) { |
27
|
|
|
throw new \RuntimeException(sprintf("missing config: %s:%s", $category, $setting)); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
if (!is_scalar($value)) { |
31
|
|
|
throw new \RuntimeException( |
32
|
|
|
sprintf("invalid config: %s:%s, type: %s", $category, $setting, gettype($value)) |
33
|
|
|
); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
return $value; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Gets a setting, but throws an exception if it's empty |
41
|
|
|
* |
42
|
|
|
* @param string $category The category of setting to get |
43
|
|
|
* @param string $setting The name of the setting to get |
44
|
|
|
* @param mixed $default The default value if one does not exist |
45
|
|
|
* |
46
|
|
|
* @return string|int|float|bool The value of the setting |
47
|
|
|
*/ |
48
|
|
|
public static function reset(string $category, string $setting, $default = null) |
49
|
|
|
{ |
50
|
|
|
$value = parent::get($category, $setting, $default); |
51
|
|
|
|
52
|
|
|
if ($value === null) { |
53
|
|
|
throw new \RuntimeException(sprintf("missing config: %s:%s", $category, $setting)); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
if (!is_scalar($value)) { |
57
|
|
|
throw new \RuntimeException( |
58
|
|
|
sprintf("invalid config: %s:%s, type: %s", $category, $setting, gettype($value)) |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $value; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|