1 | <?php |
||
14 | class Config implements \ArrayAccess |
||
15 | { |
||
16 | /** |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $config = array(); |
||
20 | |||
21 | /** |
||
22 | * @var array |
||
23 | */ |
||
24 | protected $defaults = array( |
||
25 | 'build_path' => 'build/cauditor', |
||
26 | 'exclude_folders' => array('tests', 'vendor'), |
||
27 | ); |
||
28 | |||
29 | /** |
||
30 | * List of config keys that denote paths, so they can be normalized |
||
31 | * (= turned into "relative to project root" instead of "relative to config |
||
32 | * file") |
||
33 | * |
||
34 | * @var string[] |
||
35 | */ |
||
36 | protected $paths = array('build_path', 'exclude_folders'); |
||
37 | |||
38 | /** |
||
39 | * @param string $project Project root path. |
||
40 | * @param string $config Config YML file path. |
||
41 | */ |
||
42 | public function __construct($project, $config = null) |
||
61 | |||
62 | /** |
||
63 | * Normalize all relative paths by prefixing them with the project path. |
||
64 | * |
||
65 | * @param string|string[] $value |
||
66 | * |
||
67 | * @return string|string[] |
||
68 | */ |
||
69 | protected function normalizePath($value) |
||
83 | |||
84 | /** |
||
85 | * @param string $path Path to config file. |
||
86 | * |
||
87 | * @return array |
||
88 | */ |
||
89 | protected function readConfig($path) |
||
112 | |||
113 | /** |
||
114 | * {@inheritdoc. |
||
115 | */ |
||
116 | public function offsetExists($offset) |
||
120 | |||
121 | /** |
||
122 | * {@inheritdoc. |
||
123 | */ |
||
124 | public function offsetGet($offset) |
||
128 | |||
129 | /** |
||
130 | * {@inheritdoc. |
||
131 | */ |
||
132 | public function offsetSet($offset, $value) |
||
136 | |||
137 | /** |
||
138 | * {@inheritdoc. |
||
139 | */ |
||
140 | public function offsetUnset($offset) |
||
144 | } |
||
145 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: