1 | <?php |
||
22 | */ |
||
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 |
|
204 | { |
||
205 | 1 | $mode = 0; |
|
206 | $mapper = [ |
||
207 | 1 | 0 => [], // type like d as directory, l as link etc. |
|
208 | // Owner |
||
209 | 1 => ['r' => 0400], |
||
210 | 2 => ['w' => 0200], |
||
211 | 3 => [ |
||
212 | 'x' => 0100, |
||
213 | 's' => 04100, |
||
214 | 'S' => 04000 |
||
215 | ], |
||
216 | // Group |
||
217 | 4 => ['r' => 040], |
||
218 | 5 => ['w' => 020], |
||
219 | 6 => [ |
||
220 | 'x' => 010, |
||
221 | 's' => 02010, |
||
222 | 'S' => 02000 |
||
223 | ], |
||
224 | // World |
||
318 |