1 | <?php |
||
53 | abstract class AbstractResource |
||
54 | { |
||
55 | /** |
||
56 | * Part or part aggregate |
||
57 | * |
||
58 | * @var PartInterface |
||
59 | */ |
||
60 | protected $part = null; |
||
61 | |||
62 | /** |
||
63 | * Reader instance |
||
64 | * |
||
65 | * @var ReaderInterface |
||
66 | */ |
||
67 | protected $reader = null; |
||
68 | /** |
||
69 | * File hydrator |
||
70 | * |
||
71 | * @var HydratorInterface |
||
72 | */ |
||
73 | private $hydrator = null; |
||
74 | |||
75 | /******************************************************************************* |
||
76 | * PUBLIC METHODS |
||
77 | *******************************************************************************/ |
||
78 | |||
79 | /** |
||
80 | * Private constructor |
||
81 | * |
||
82 | * @param HydratorInterface|array|string $hydrator File hydrator |
||
83 | * @param ReaderInterface $reader Reader instance |
||
84 | */ |
||
85 | 71 | protected function __construct($hydrator, ReaderInterface $reader = null) |
|
100 | |||
101 | /** |
||
102 | * Set a reader instance for this file |
||
103 | * |
||
104 | * @param ReaderInterface $reader Reader instance |
||
105 | * @return AbstractResource Self reference |
||
106 | */ |
||
107 | 51 | public function load(ReaderInterface $reader) |
|
113 | |||
114 | /** |
||
115 | * Reset the file |
||
116 | * |
||
117 | * @return void |
||
118 | */ |
||
119 | 51 | protected function reset() |
|
123 | |||
124 | /** |
||
125 | * Dump this files contents into a writer |
||
126 | * |
||
127 | * @param WriterInterface $writer Writer instance |
||
128 | * @return AbstractResource Self reference |
||
129 | */ |
||
130 | 12 | public function dump(WriterInterface $writer) |
|
135 | |||
136 | /** |
||
137 | * Return the part's content |
||
138 | * |
||
139 | * @param string $part Part path |
||
140 | * @return string Part content |
||
141 | */ |
||
142 | 46 | public function getPart($part = '/') |
|
148 | |||
149 | /******************************************************************************* |
||
150 | * PRIVATE METHODS |
||
151 | *******************************************************************************/ |
||
152 | |||
153 | /** |
||
154 | * Set the content of a particular part |
||
155 | * |
||
156 | * @param mixed $data Content |
||
157 | * @param string $part Part path |
||
158 | * @return AbstractResource Self reference |
||
159 | */ |
||
160 | 12 | public function setPart($data, $part = '/') |
|
165 | |||
166 | /** |
||
167 | * Split a part path string into path identifiers |
||
168 | * |
||
169 | * @param string $path Part path string |
||
170 | * @return array Part path identifiers |
||
171 | */ |
||
172 | 67 | protected function partPath($path) |
|
183 | |||
184 | /** |
||
185 | * Lazy-hydrate and return the main file part |
||
186 | * |
||
187 | * @return PartInterface Main file part |
||
188 | */ |
||
189 | 66 | protected function part() |
|
198 | |||
199 | /** |
||
200 | * Magic caller for part methods |
||
201 | * |
||
202 | * @param string $name Part method name |
||
203 | * @param array $arguments Part method arguments |
||
204 | * @return mixed|AbstractResource Self reference |
||
205 | * @throw RuntimeException If an invalid file method is called |
||
206 | * @throw RuntimeException If an invalid file part method is called |
||
207 | */ |
||
208 | 32 | public function __call($name, array $arguments) |
|
220 | |||
221 | /** |
||
222 | * Call a method on one of the subparts |
||
223 | * |
||
224 | * @param array $partMethod Part method components |
||
225 | * @param array $arguments Part method arguments |
||
226 | * @return mixed|AbstractResource Getter result / self reference |
||
227 | */ |
||
228 | 31 | protected function callPartMethod(array $partMethod, array $arguments) |
|
235 | |||
236 | /** |
||
237 | * Call a non-getter method on one of the subparts |
||
238 | * |
||
239 | * @param string $partMethod Part method |
||
240 | * @param array $arguments Part method arguments |
||
241 | * @return AbstractResource Self reference |
||
242 | */ |
||
243 | 16 | protected function callNonGetterPartMethod($partMethod, array $arguments) |
|
249 | |||
250 | /** |
||
251 | * Call a getter method on one of the subparts |
||
252 | * |
||
253 | * @param string $partMethod Part method |
||
254 | * @param array $arguments Part method arguments |
||
255 | * @return mixed Getter result |
||
256 | */ |
||
257 | 19 | protected function callGetterPartMethod($partMethod, array $arguments) |
|
262 | } |
||
263 |