1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Phoole (PHP7.2+) |
5
|
|
|
* |
6
|
|
|
* @category Library |
7
|
|
|
* @package Phoole\Config |
8
|
|
|
* @copyright Copyright (c) 2019 Hong Zhang |
9
|
|
|
*/ |
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Phoole\Config; |
13
|
|
|
|
14
|
|
|
use Phoole\Config\Util\Loader; |
15
|
|
|
use Phoole\Config\Util\ArrayAccessTrait; |
16
|
|
|
use Phoole\Base\Reference\ReferenceInterface; |
17
|
|
|
use Phoole\Base\Reference\ReferenceTrait; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Config |
21
|
|
|
* |
22
|
|
|
* @package Phoole\Config |
23
|
|
|
*/ |
24
|
|
|
class Config implements ConfigInterface, ReferenceInterface, \ArrayAccess |
25
|
|
|
{ |
26
|
|
|
use ReferenceTrait; |
27
|
|
|
use ArrayAccessTrait; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var Loader |
31
|
|
|
*/ |
32
|
|
|
protected $loader; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var Tree |
|
|
|
|
36
|
|
|
*/ |
37
|
|
|
protected $tree; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
private $cached_id; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var mixed |
46
|
|
|
*/ |
47
|
|
|
private $cached_value; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Constructor |
51
|
|
|
* |
52
|
|
|
* @param string $rootDir |
53
|
|
|
* @param string $environment |
54
|
|
|
*/ |
55
|
|
|
public function __construct(string $rootDir, string $environment = '') |
56
|
|
|
{ |
57
|
|
|
$this->loader = (new Loader($rootDir, $environment))->load(); |
58
|
|
|
$this->tree = $this->loader->getTree(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritDoc} |
63
|
|
|
*/ |
64
|
|
|
public function get(string $id) |
65
|
|
|
{ |
66
|
|
|
if ($this->has($id)) { |
67
|
|
|
$val = $this->cached_value; |
68
|
|
|
$this->deReference($val); |
69
|
|
|
return $val; |
70
|
|
|
} |
71
|
|
|
return null; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritDoc} |
76
|
|
|
*/ |
77
|
|
|
public function has(string $id): bool |
78
|
|
|
{ |
79
|
|
|
if ($id === $this->cached_id) { |
80
|
|
|
return null !== $this->cached_value; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$this->cached_id = $id; |
84
|
|
|
$this->cached_value = null; |
85
|
|
|
|
86
|
|
|
try { |
87
|
|
|
$this->cached_value = $this->tree->get($id); |
88
|
|
|
} catch (\Exception $e) { |
89
|
|
|
throw new \RuntimeException($e->getMessage()); |
90
|
|
|
} |
91
|
|
|
return null !== $this->cached_value; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* {@inheritDoc} |
96
|
|
|
*/ |
97
|
|
|
public function with(string $id, $value): ConfigInterface |
98
|
|
|
{ |
99
|
|
|
$new = clone $this; |
100
|
|
|
$new->tree->add($id, $value); |
101
|
|
|
return $new; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* {@inheritDoc} |
106
|
|
|
*/ |
107
|
|
|
protected function getReference(string $name) |
108
|
|
|
{ |
109
|
|
|
return $this->get($name); |
|
|
|
|
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function __clone() |
113
|
|
|
{ |
114
|
|
|
$this->loader = clone $this->loader; |
115
|
|
|
$this->tree = $this->loader->getTree(); |
|
|
|
|
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths