1 | <?php |
||
15 | class Config extends Collection implements ConfigInterface |
||
16 | { |
||
17 | /** |
||
18 | * Array of parser instances |
||
19 | * @var array |
||
20 | */ |
||
21 | protected static $parsers = []; |
||
22 | |||
23 | /** |
||
24 | * Array of supported file format parsers |
||
25 | * @var array |
||
26 | */ |
||
27 | protected static $supportedFileParsers = [ |
||
28 | PHPParser::class, |
||
29 | IniParser::class, |
||
30 | JsonParser::class |
||
31 | ]; |
||
32 | |||
33 | public function __construct($path = null) |
||
38 | |||
39 | /** |
||
40 | * {@inheritdoc} |
||
41 | */ |
||
42 | public function load($path) |
||
50 | |||
51 | /** |
||
52 | * {@inheritdoc} |
||
53 | */ |
||
54 | public function dump($file) |
||
59 | |||
60 | /** |
||
61 | * Parse a configuration file or directory to an array |
||
62 | * @param string $path |
||
63 | * @return array |
||
64 | * @deprecated |
||
65 | */ |
||
66 | public function parse($path) |
||
70 | |||
71 | /** |
||
72 | * Parse a configuration file or directory to an array |
||
73 | * @param string $path |
||
74 | * @return array |
||
75 | */ |
||
76 | protected function parseConfiguration($path) |
||
77 | { |
||
78 | $files = $this->findConfigurationFiles($path); |
||
79 | $data = []; |
||
80 | foreach ($files as $file) { |
||
81 | $extension = pathinfo($file, PATHINFO_EXTENSION); |
||
82 | $data = array_merge($data, static::getParser($extension)->parse($file)); |
||
83 | } |
||
84 | return $data; |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * finds all supported configuration files at the directory |
||
89 | * @param string $path |
||
90 | * @throws InvalidFileException |
||
91 | * @return array |
||
92 | */ |
||
93 | protected function findConfigurationFiles($path) |
||
108 | |||
109 | /** |
||
110 | * Gets a file parser by its extension |
||
111 | * @param string $extension |
||
112 | * @throws UnsupportedFormatException |
||
113 | * @return ParserInterface |
||
114 | */ |
||
115 | protected static function getParser($extension) |
||
128 | } |
||
129 |