-
Notifications
You must be signed in to change notification settings - Fork 0
/
PhpIni.php
49 lines (43 loc) · 1.13 KB
/
PhpIni.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
<?php
declare(strict_types=1);
namespace Peak\Common;
use function ini_set;
use function is_array;
use function print_r;
class PhpIni
{
/**
* PhpIni constructor.
* @param array $definitions
* @param bool $strict
* @throws \Exception
*/
public function __construct(array $definitions, bool $strict = false)
{
if (empty($definitions)) {
return;
}
foreach ($definitions as $setting => $val) {
if (!is_array($val)) {
$this->set($setting, $val, $strict);
} else {
foreach ($val as $k => $v) {
$this->set($setting.'.'.$k, $v, $strict);
}
}
}
}
/**
* @param string $option
* @param mixed $value
* @param bool $strict
* @throws \Exception
*/
private function set(string $option, $value, bool $strict = false)
{
$result = @ini_set($option, (string)$value);
if ($strict && $result === false) {
throw new \Exception('Fail to set php option '.$option.' to "'.print_r($value, true).'"');
}
}
}