|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace HexMakina\LeMarchand; |
|
4
|
|
|
|
|
5
|
|
|
use \Psr\Container\ContainerInterface; |
|
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
class LeMarchand implements ContainerInterface |
|
8
|
|
|
{ |
|
9
|
|
|
private $configurations = []; |
|
10
|
|
|
|
|
11
|
|
|
public function __construct($settings) |
|
12
|
|
|
{ |
|
13
|
|
|
$this->configurations['settings'] = $settings; |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
public function __debugInfo() : array |
|
17
|
|
|
{ |
|
18
|
|
|
$dbg = get_object_vars($this); |
|
19
|
|
|
$dbg['configurations']['template_engine'] = isset($dbg['configurations']['template_engine'])? get_class($dbg['configurations']['template_engine']) : 'NOT SET'; |
|
20
|
|
|
|
|
21
|
|
|
return $dbg; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function register($configuration, $instance) |
|
25
|
|
|
{ |
|
26
|
|
|
$this->configurations[$configuration] = $instance; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function has($configuration) |
|
30
|
|
|
{ |
|
31
|
|
|
return isset($this->configurations[$configuration]); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function get($configuration) |
|
35
|
|
|
{ |
|
36
|
|
|
|
|
37
|
|
|
if(!is_string($configuration)) |
|
38
|
|
|
throw new LamentException($configuration); |
|
39
|
|
|
|
|
40
|
|
|
if($this->has($configuration)) |
|
41
|
|
|
return $this->configurations[$configuration]; |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
// fallbacks |
|
45
|
|
|
if(preg_match('/^settings\./', $configuration, $m) === 1) |
|
46
|
|
|
{ |
|
47
|
|
|
$ret = $this->configurations; |
|
48
|
|
|
foreach(explode('.', $configuration) as $k) |
|
49
|
|
|
{ |
|
50
|
|
|
if(!isset($ret[$k])) |
|
51
|
|
|
throw new ConfigurationException($configuration); |
|
52
|
|
|
$ret = $ret[$k]; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return $ret; |
|
56
|
|
|
} |
|
57
|
|
|
elseif(class_exists($configuration)) // auto create instances |
|
58
|
|
|
{ |
|
59
|
|
|
|
|
60
|
|
|
$rc = new \ReflectionClass($configuration); |
|
61
|
|
|
|
|
62
|
|
|
$construction_args = []; |
|
63
|
|
|
$instance = null; |
|
64
|
|
|
if(!is_null($rc->getConstructor())) |
|
65
|
|
|
{ |
|
66
|
|
|
foreach($rc->getConstructor()->getParameters() as $param) |
|
67
|
|
|
{ |
|
68
|
|
|
$construction_args []= $this->get($param->getType().''); |
|
69
|
|
|
} |
|
70
|
|
|
$instance = $rc->newInstanceArgs($construction_args); |
|
71
|
|
|
} |
|
72
|
|
|
else |
|
73
|
|
|
$instance = $rc->newInstanceArgs(); |
|
74
|
|
|
|
|
75
|
|
|
if($rc->hasMethod('set_container')) |
|
76
|
|
|
$instance->set_container($this); |
|
77
|
|
|
|
|
78
|
|
|
return $instance; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
throw new ConfigurationException($configuration); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
|
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