1 | <?php |
||
20 | class YamlReader |
||
21 | { |
||
22 | |||
23 | /** |
||
24 | * The path for the cache files. |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $cachePath; |
||
28 | |||
29 | /** |
||
30 | * Gets an absolute path for a cache file. |
||
31 | * |
||
32 | * @param string $fileName |
||
33 | * the file to cache |
||
34 | * @return string |
||
35 | * the absolute path of the cache file |
||
36 | */ |
||
37 | 83 | protected function getCacheFile($fileName) |
|
41 | |||
42 | /** |
||
43 | * Reads the content of the cached file if it exists. |
||
44 | * |
||
45 | * @param string $fileName |
||
46 | * the cache file to read from |
||
47 | * @return null|array |
||
48 | * the cached data structure or null if the cache file was not available |
||
49 | */ |
||
50 | 83 | protected function readFromCache($fileName) |
|
61 | |||
62 | /** |
||
63 | * Writes the given content to a cached PHP file. |
||
64 | * |
||
65 | * @param string $fileName |
||
66 | * the original filename |
||
67 | * @param array $content |
||
68 | * the content to cache |
||
69 | */ |
||
70 | 81 | protected function writeToCache($fileName, $content) |
|
83 | |||
84 | /** |
||
85 | * YamlReader constructor. |
||
86 | * @param string|null $cachePath |
||
87 | * if given, the path for the cache files which should be a writable directory |
||
88 | */ |
||
89 | 83 | public function __construct($cachePath) |
|
93 | |||
94 | /** |
||
95 | * Reads and returns the contents of the given Yaml file. If |
||
96 | * it goes wrong, it throws an exception. |
||
97 | * |
||
98 | * @param string $fileName |
||
99 | * the file to read |
||
100 | * |
||
101 | * @return array |
||
102 | * the file contents |
||
103 | * |
||
104 | * @throws \RuntimeException |
||
105 | * thrown if the file could not be read or parsed |
||
106 | */ |
||
107 | 83 | public function read($fileName) |
|
126 | |||
127 | } |
||
128 |