1 | <?php |
||
24 | abstract class AbstractAdapter implements AdapterInterface |
||
25 | { |
||
26 | /** @var ResourceManager */ |
||
27 | protected $manager; |
||
28 | |||
29 | /** |
||
30 | * The version probe |
||
31 | * |
||
32 | * @var VersionProbeInterface |
||
33 | */ |
||
34 | protected $probe; |
||
35 | |||
36 | public function __construct(ResourceManager $manager) |
||
40 | |||
41 | /** |
||
42 | * @inheritdoc |
||
43 | */ |
||
44 | public function open($path) |
||
50 | |||
51 | /** |
||
52 | * @inheritdoc |
||
53 | */ |
||
54 | public function create($path, $files = null, $recursive = true) |
||
60 | |||
61 | /** |
||
62 | * @inheritdoc |
||
63 | */ |
||
64 | public function listMembers(ResourceInterface $resource) |
||
70 | |||
71 | /** |
||
72 | * @inheritdoc |
||
73 | */ |
||
74 | public function add(ResourceInterface $resource, $files, $recursive = true) |
||
80 | |||
81 | /** |
||
82 | * @inheritdoc |
||
83 | */ |
||
84 | public function remove(ResourceInterface $resource, $files) |
||
90 | |||
91 | /** |
||
92 | * @inheritdoc |
||
93 | */ |
||
94 | public function extract(ResourceInterface $resource, $to = null) |
||
100 | |||
101 | /** |
||
102 | * @inheritdoc |
||
103 | */ |
||
104 | public function extractMembers(ResourceInterface $resource, $members, $to = null, $overwrite = false) |
||
110 | |||
111 | /** |
||
112 | * Returns the version probe used by this adapter |
||
113 | * |
||
114 | * @return VersionProbeInterface |
||
115 | */ |
||
116 | public function getVersionProbe() |
||
120 | |||
121 | /** |
||
122 | * Sets the version probe used by this adapter |
||
123 | * |
||
124 | * @param VersionProbeInterface $probe |
||
125 | * |
||
126 | * @return VersionProbeInterface |
||
127 | */ |
||
128 | public function setVersionProbe(VersionProbeInterface $probe) |
||
134 | |||
135 | /** |
||
136 | * @inheritdoc |
||
137 | */ |
||
138 | public function isSupported() |
||
148 | |||
149 | /** |
||
150 | * Throws an exception is the current adapter is not supported |
||
151 | * |
||
152 | * @throws RuntimeException |
||
153 | */ |
||
154 | protected function requireSupport() |
||
160 | |||
161 | /** |
||
162 | * Change current working directory to another |
||
163 | * |
||
164 | * @param string $target the target directory |
||
165 | * |
||
166 | * @return AdapterInterface |
||
167 | * |
||
168 | * @throws RuntimeException In case of failure |
||
169 | */ |
||
170 | protected function chdir($target) |
||
178 | |||
179 | /** |
||
180 | * Creates a resource given a path |
||
181 | * |
||
182 | * @param string $path |
||
183 | * |
||
184 | * @return ResourceInterface |
||
185 | */ |
||
186 | abstract protected function createResource($path); |
||
187 | |||
188 | /** |
||
189 | * Do the removal after having check that the current adapter is supported |
||
190 | * |
||
191 | * @param ResourceInterface $resource |
||
192 | * @param array $files |
||
193 | * |
||
194 | * @return array |
||
195 | */ |
||
196 | abstract protected function doRemove(ResourceInterface $resource, $files); |
||
197 | |||
198 | /** |
||
199 | * Do the add after having check that the current adapter is supported |
||
200 | * |
||
201 | * @param ResourceInterface $resource |
||
202 | * @param array $files |
||
203 | * @param bool $recursive |
||
204 | * |
||
205 | * @return array |
||
206 | */ |
||
207 | abstract protected function doAdd(ResourceInterface $resource, $files, $recursive); |
||
208 | |||
209 | /** |
||
210 | * Do the extract after having check that the current adapter is supported |
||
211 | * |
||
212 | * @param ResourceInterface $resource |
||
213 | * @param $to |
||
214 | * |
||
215 | * @return \SplFileInfo The extracted archive |
||
216 | */ |
||
217 | abstract protected function doExtract(ResourceInterface $resource, $to); |
||
218 | |||
219 | /** |
||
220 | * Do the extract members after having check that the current adapter is supported |
||
221 | * |
||
222 | * @param ResourceInterface $resource |
||
223 | * @param string|string[] $members |
||
224 | * @param string $to |
||
225 | * @param bool $overwrite |
||
226 | * |
||
227 | * @return \SplFileInfo The extracted archive |
||
228 | */ |
||
229 | abstract protected function doExtractMembers(ResourceInterface $resource, $members, $to, $overwrite = false); |
||
230 | |||
231 | /** |
||
232 | * Do the list members after having check that the current adapter is supported |
||
233 | * |
||
234 | * @param ResourceInterface $resource |
||
235 | * |
||
236 | * @return array |
||
237 | */ |
||
238 | abstract protected function doListMembers(ResourceInterface $resource); |
||
239 | |||
240 | /** |
||
241 | * Do the create after having check that the current adapter is supported |
||
242 | * |
||
243 | * @param string $path |
||
244 | * @param string $file |
||
245 | * @param bool $recursive |
||
246 | * |
||
247 | * @return ArchiveInterface |
||
248 | */ |
||
249 | abstract protected function doCreate($path, $file, $recursive); |
||
250 | |||
251 | /** |
||
252 | * Makes the target path absolute as the adapters might have a different directory |
||
253 | * |
||
254 | * @param string $path The path to convert |
||
255 | * |
||
256 | * @return string The absolute path |
||
257 | * |
||
258 | * @throws InvalidArgumentException In case the path is not writable or does not exist |
||
259 | */ |
||
260 | private function makeTargetAbsolute($path) |
||
273 | } |
||
274 |