| @@ 7-26 (lines=20) @@ | ||
| 4 | use SamBurns\ConfigFileParser\File\ParsableFile; |
|
| 5 | use SamBurns\ConfigFileParser\FileReading\FileContentsRetriever; |
|
| 6 | ||
| 7 | class IniFile implements ParsableFile |
|
| 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 SamBurns\ConfigFileParser\File\ParsableFile; |
|
| 5 | use SamBurns\ConfigFileParser\FileReading\FileContentsRetriever; |
|
| 6 | ||
| 7 | class JsonFile implements ParsableFile |
|
| 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 | ||