@@ 7-26 (lines=20) @@ | ||
4 | use ConfigTree\FileParsing\ArrayableFile; |
|
5 | use ConfigTree\FileParsing\Reading\FileContentsRetriever; |
|
6 | ||
7 | class IniFile implements ArrayableFile |
|
8 | { |
|
9 | /** @var string */ |
|
10 | private $path; |
|
11 | ||
12 | /** @var FileContentsRetriever */ |
|
13 | private $fileContentsRetriever; |
|
14 | ||
15 | public function __construct(string $path, FileContentsRetriever $fileContentsRetriever) |
|
16 | { |
|
17 | $this->path = $path; |
|
18 | $this->fileContentsRetriever = $fileContentsRetriever; |
|
19 | } |
|
20 | ||
21 | public function toArray() : array |
|
22 | { |
|
23 | $fileContents = $this->fileContentsRetriever->fileGetContents($this->path); |
|
24 | return parse_ini_string($fileContents); |
|
25 | } |
|
26 | } |
|
27 |
@@ 7-26 (lines=20) @@ | ||
4 | use ConfigTree\FileParsing\ArrayableFile; |
|
5 | use ConfigTree\FileParsing\Reading\FileContentsRetriever; |
|
6 | ||
7 | class JsonFile implements ArrayableFile |
|
8 | { |
|
9 | /** @var string */ |
|
10 | private $path; |
|
11 | ||
12 | /** @var FileContentsRetriever */ |
|
13 | private $fileContentsRetriever; |
|
14 | ||
15 | public function __construct(string $path, FileContentsRetriever $fileContentsRetriever) |
|
16 | { |
|
17 | $this->path = $path; |
|
18 | $this->fileContentsRetriever = $fileContentsRetriever; |
|
19 | } |
|
20 | ||
21 | public function toArray() : array |
|
22 | { |
|
23 | $fileContents = $this->fileContentsRetriever->fileGetContents($this->path); |
|
24 | return json_decode($fileContents, true); |
|
25 | } |
|
26 | } |
|
27 |