1 | <?php |
||
10 | class GameapAdapter extends GameapAbstractAdapter |
||
11 | { |
||
12 | /** |
||
13 | * @var array |
||
14 | */ |
||
15 | protected $configurable = [ |
||
16 | 'host', |
||
17 | 'port', |
||
18 | 'username', |
||
19 | 'password', |
||
20 | 'serverCertificate', |
||
21 | 'localCertificate', |
||
22 | 'privateKey', |
||
23 | 'privateKeyPass', |
||
24 | 'timeout', |
||
25 | 'root', |
||
26 | ]; |
||
27 | |||
28 | /** |
||
29 | * @return bool |
||
30 | * @throws \Exception |
||
31 | */ |
||
32 | 70 | public function isConnected() |
|
36 | |||
37 | /** |
||
38 | * @inheritdoc |
||
39 | */ |
||
40 | 3 | public function write($path, $contents, Config $config) |
|
48 | |||
49 | /** |
||
50 | * @inheritdoc |
||
51 | */ |
||
52 | 3 | public function writeStream($path, $resource, Config $config) |
|
60 | |||
61 | /** |
||
62 | * @inheritdoc |
||
63 | */ |
||
64 | 3 | public function update($path, $contents, Config $config) |
|
68 | |||
69 | /** |
||
70 | * @inheritdoc |
||
71 | */ |
||
72 | 3 | public function updateStream($path, $resource, Config $config) |
|
76 | |||
77 | /** |
||
78 | * Upload a file. |
||
79 | * |
||
80 | * @param string $path |
||
81 | * @param string|resource $contents |
||
82 | * @param Config $config |
||
83 | * @return bool |
||
84 | */ |
||
85 | 15 | public function upload($path, $contents, Config $config) |
|
107 | |||
108 | /** |
||
109 | * @inheritdoc |
||
110 | */ |
||
111 | 3 | public function rename($path, $newpath) |
|
120 | |||
121 | /** |
||
122 | * @inheritdoc |
||
123 | */ |
||
124 | 3 | public function copy($path, $newpath) |
|
131 | |||
132 | /** |
||
133 | * @inheritdoc |
||
134 | */ |
||
135 | 9 | public function delete($path) |
|
141 | |||
142 | /** |
||
143 | * @inheritdoc |
||
144 | */ |
||
145 | 3 | public function deleteDir($dirname) |
|
149 | |||
150 | /** |
||
151 | * @inheritdoc |
||
152 | */ |
||
153 | 4 | public function createDir($dirname, Config $config) |
|
166 | |||
167 | /** |
||
168 | * @inheritdoc |
||
169 | */ |
||
170 | 6 | public function setVisibility($path, $visibility) |
|
171 | { |
||
172 | 6 | $location = $this->applyPathPrefix($path); |
|
173 | |||
174 | 6 | $visibility = ucfirst($visibility); |
|
175 | |||
176 | 6 | if (! isset($this->{'perm'.$visibility})) { |
|
177 | 3 | throw new InvalidArgumentException('Unknown visibility: '.$visibility); |
|
178 | } |
||
179 | |||
180 | 3 | $permissions = $this->{'perm'.$visibility}; |
|
181 | |||
182 | 3 | if ($this->getConnection()->chmod($permissions, $location)) { |
|
183 | 3 | return compact('path', 'visibility'); |
|
184 | } else { |
||
185 | 3 | return false; |
|
186 | 1 | } |
|
187 | } |
||
188 | |||
189 | /** |
||
190 | * @inheritdoc |
||
191 | */ |
||
192 | 38 | public function has($path) |
|
197 | |||
198 | /** |
||
199 | * @inheritdoc |
||
200 | */ |
||
201 | 6 | public function read($path) |
|
210 | |||
211 | /** |
||
212 | * @inheritdoc |
||
213 | */ |
||
214 | 6 | public function readStream($path) |
|
222 | |||
223 | |||
224 | /** |
||
225 | * @inheritdoc |
||
226 | */ |
||
227 | 6 | public function listContents($directory = '', $recursive = false) |
|
228 | { |
||
229 | 6 | $fullPath = $this->applyPathPrefix($directory); |
|
230 | 6 | $listing = $this->getConnection()->directoryContents($fullPath); |
|
231 | |||
232 | 6 | $result = []; |
|
233 | 6 | foreach ($listing as $file) { |
|
234 | 6 | $path = empty($directory) ? $file['name'] : $directory . $this->pathSeparator . ltrim($file['name'], $this->pathSeparator); |
|
235 | 6 | $result[] = $this->normalizeListingObject($path, $file); |
|
236 | |||
237 | 6 | if ($recursive && isset($file['type']) && $file['type'] === 'dir') { |
|
238 | 4 | $result = array_merge($result, $this->listContents($path)); |
|
239 | 2 | } |
|
240 | 4 | } |
|
241 | |||
242 | 6 | return $result; |
|
243 | } |
||
244 | |||
245 | |||
246 | /** |
||
247 | * @inheritdoc |
||
248 | */ |
||
249 | 12 | public function getMetadata($path) |
|
264 | |||
265 | |||
266 | /** |
||
267 | * @inheritdoc |
||
268 | */ |
||
269 | 3 | public function getSize($path) |
|
273 | |||
274 | |||
275 | /** |
||
276 | * @inheritdoc |
||
277 | */ |
||
278 | 3 | public function getMimetype($path) |
|
291 | |||
292 | |||
293 | /** |
||
294 | * @inheritdoc |
||
295 | */ |
||
296 | 3 | public function getTimestamp($path) |
|
300 | |||
301 | |||
302 | /** |
||
303 | * @inheritdoc |
||
304 | */ |
||
305 | 6 | public function getVisibility($path) |
|
309 | } |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.