1 | <?php |
||
23 | abstract class AbstractServiceAdapter implements ServiceInterface |
||
24 | { |
||
25 | /** @var string */ |
||
26 | protected $localPath = __DIR__; |
||
27 | /** @var array */ |
||
28 | protected $options = []; |
||
29 | |||
30 | /** |
||
31 | * ServiceAdapter constructor. |
||
32 | * |
||
33 | * @param ConfigurationInterface $configuration |
||
34 | */ |
||
35 | 9 | public function __construct(ConfigurationInterface $configuration) |
|
39 | |||
40 | /** |
||
41 | * Connect and login to remote host. |
||
42 | * |
||
43 | * @return ServiceInterface |
||
44 | */ |
||
45 | abstract public function connect() : ServiceInterface; |
||
46 | |||
47 | /** |
||
48 | * Disconnect from remote host. |
||
49 | * |
||
50 | * @return ServiceInterface |
||
51 | */ |
||
52 | abstract public function disconnect() : ServiceInterface; |
||
53 | |||
54 | /** |
||
55 | * Sets an option data. |
||
56 | * |
||
57 | * @param string $key |
||
58 | * @param mixed $value |
||
59 | * @return ServiceInterface |
||
60 | */ |
||
61 | 1 | public function setOption(string $key, $value) : ServiceInterface |
|
66 | |||
67 | /** |
||
68 | * Sets a group of options. |
||
69 | * |
||
70 | * @param array $options |
||
71 | * @return ServiceInterface |
||
72 | */ |
||
73 | 9 | public function setOptions(array $options) : ServiceInterface |
|
78 | |||
79 | /** |
||
80 | * Gets a specific option data. |
||
81 | * |
||
82 | * @param string $key |
||
83 | * @param mixed $default |
||
84 | * @return mixed |
||
85 | */ |
||
86 | 1 | public function getOption(string $key, $default = null) |
|
90 | |||
91 | /** |
||
92 | * Toggles connection security level. |
||
93 | * |
||
94 | * @param bool $state |
||
95 | * @return ServiceInterface |
||
96 | */ |
||
97 | abstract public function setSecureConnection(bool $state) : ServiceInterface; |
||
98 | |||
99 | /** |
||
100 | * Toggles connection passive mode. |
||
101 | * |
||
102 | * @param bool $state |
||
103 | * @return ServiceInterface |
||
104 | */ |
||
105 | abstract public function setPassiveMode(bool $state) : ServiceInterface; |
||
106 | |||
107 | /** |
||
108 | * Sets remote path. |
||
109 | * |
||
110 | * @param string $path |
||
111 | * @return ServiceInterface |
||
112 | */ |
||
113 | abstract public function setRemotePath(string $path) : ServiceInterface; |
||
114 | |||
115 | /** |
||
116 | * Gets remote path. |
||
117 | * |
||
118 | * @return string |
||
119 | */ |
||
120 | abstract public function getRemotePath() : string; |
||
121 | |||
122 | /** |
||
123 | * Sets local path. |
||
124 | * |
||
125 | * @param string $path |
||
126 | * @return ServiceInterface |
||
127 | */ |
||
128 | 6 | public function setLocalPath(string $path) : ServiceInterface |
|
157 | |||
158 | /** |
||
159 | * Checks local file, and generates new unique name if necessary. |
||
160 | * |
||
161 | * @param string $localFileName |
||
162 | * @param bool $forceUnique |
||
163 | * @throws RuntimeException |
||
164 | */ |
||
165 | 1 | protected function checkLocalFile(string&$localFileName, bool $forceUnique = false) : void |
|
196 | |||
197 | /** |
||
198 | * Converts file rights string into octal value. |
||
199 | * |
||
200 | * @param string $permissions The UNIX-style permission string, e.g.: 'drwxr-xr-x' |
||
201 | * @return string |
||
202 | */ |
||
203 | 1 | protected function getOctalChmod(string $permissions) : string |
|
240 | |||
241 | /** |
||
242 | * Check remote file name. |
||
243 | * |
||
244 | * @param string $remoteFileName |
||
245 | */ |
||
246 | abstract protected function checkRemoteFile(string&$remoteFileName) : void; |
||
247 | |||
248 | /** |
||
249 | * Gets local path. |
||
250 | * |
||
251 | * @return string |
||
252 | */ |
||
253 | 1 | public function getLocalPath() : string |
|
257 | |||
258 | /** |
||
259 | * Lists remote path. |
||
260 | * |
||
261 | * @param null|string $path |
||
262 | * @param bool|null $changeToDirectory |
||
263 | * @return array |
||
264 | */ |
||
265 | abstract public function getRemoteFileList(? string $path, ? bool $changeToDirectory) : array; |
||
266 | |||
267 | /** |
||
268 | * Uploads file to remote host. |
||
269 | * |
||
270 | * @see self::setRemotePath |
||
271 | * @see self::setLocalPath |
||
272 | * |
||
273 | * @param string $sourceFileName |
||
274 | * @param string $destinationFileName |
||
275 | * @param int $fileMode |
||
276 | * @return mixed |
||
277 | */ |
||
278 | abstract public function upload( |
||
283 | |||
284 | /** |
||
285 | * Downloads file from remote host. |
||
286 | * |
||
287 | * @see self::setRemotePath |
||
288 | * @see self::setLocalPath |
||
289 | * |
||
290 | * @param string $remoteFileName |
||
291 | * @param string $localFileName |
||
292 | * @param int $fileMode |
||
293 | * @return mixed |
||
294 | */ |
||
295 | abstract public function download( |
||
300 | |||
301 | /** |
||
302 | * Moves file on remote host. |
||
303 | * |
||
304 | * @param string $currentPath |
||
305 | * @param string $newPath |
||
306 | * @return ServiceInterface |
||
307 | */ |
||
308 | abstract public function moveRemoteFile(string $currentPath, string $newPath) : ServiceInterface; |
||
309 | |||
310 | /** |
||
311 | * Deletes file on remote host. |
||
312 | * |
||
313 | * @param string $path |
||
314 | * @return ServiceInterface |
||
315 | */ |
||
316 | abstract public function deleteRemoteFile(string $path) : ServiceInterface; |
||
317 | } |
||
318 |