1 | <?php |
||
10 | class Configuration |
||
11 | { |
||
12 | /** |
||
13 | * @var [] $dirs where to look for configuration items. |
||
|
|||
14 | */ |
||
15 | protected $dirs = []; |
||
16 | |||
17 | |||
18 | |||
19 | /** |
||
20 | * Set the directories where to look for configuration |
||
21 | * items (files, directories) to load. |
||
22 | * |
||
23 | * @throws Exception when the path to any of the directories are incorrect. |
||
24 | * |
||
25 | * @param array $dirs with the path to the config directories to search in. |
||
26 | * |
||
27 | * @return self to allow chaining. |
||
28 | */ |
||
29 | 6 | public function setBaseDirectories(array $dirs): object |
|
47 | |||
48 | |||
49 | |||
50 | /** |
||
51 | * Read configuration from file or directory, if a file, look though all |
||
52 | * base dirs and use the first configuration that is found. A configuration |
||
53 | * item can be combined from a file and a directory, when available in the |
||
54 | * same base directory. |
||
55 | * |
||
56 | * The resulting configuration is always an array, its structure contains |
||
57 | * values from each individual configuration file, like this. |
||
58 | * |
||
59 | * $config = [ |
||
60 | * "base" => configuration returned from file.php, |
||
61 | * "items" => [ |
||
62 | * "file1.php" => configuration returned from dir/file1.php, |
||
63 | * "file2.php" => configuration returned from dir/file2.php, |
||
64 | * ] |
||
65 | * ] |
||
66 | * |
||
67 | * The configuration files in the directory are loaded per alphabetical |
||
68 | * order. |
||
69 | * |
||
70 | * @param string $item is a name representing the module and is used to |
||
71 | * combine the path to search for. |
||
72 | * |
||
73 | * @return mixed with returned value from the loaded configuration. |
||
74 | * |
||
75 | * @throws Exception when configuration item can not be found. |
||
76 | * @throws Exception when $dirs are empty. |
||
77 | */ |
||
78 | 5 | public function load(string $item): array |
|
116 | |||
117 | |||
118 | |||
119 | /** |
||
120 | * Read configuration a directory, loop through all files and add |
||
121 | * them into the $config array as [ |
||
122 | * "file1.php" => loaded configuration from dir/file1.php, |
||
123 | * "file2.php" => loaded configuration from dir/file2.php, |
||
124 | * ]. |
||
125 | * |
||
126 | * @param string $path is the path to the directory containing config files. |
||
127 | * |
||
128 | * @return array with configuration for each file. |
||
129 | */ |
||
130 | 2 | public function loadFromDir(string $path): array |
|
139 | } |
||
140 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.