1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package CleverStyle Framework |
4
|
|
|
* @author Nazar Mokrynskyi <[email protected]> |
5
|
|
|
* @copyright Copyright (c) 2011-2016, Nazar Mokrynskyi |
6
|
|
|
* @license MIT License, see license.txt |
7
|
|
|
*/ |
8
|
|
|
namespace cs\Storage; |
9
|
|
|
abstract class _Abstract { |
10
|
|
|
protected $connected = false; |
11
|
|
|
protected $base_url = ''; |
12
|
|
|
/** |
13
|
|
|
* Connecting to the Storage |
14
|
|
|
* |
15
|
|
|
* @param string $base_url |
16
|
|
|
* @param string $host |
17
|
|
|
* @param string $user |
18
|
|
|
* @param string $password |
19
|
|
|
*/ |
20
|
|
|
abstract public function __construct ($base_url, $host, $user = '', $password = ''); |
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Function for getting content of a directory |
23
|
|
|
* |
24
|
|
|
* @abstract |
25
|
|
|
* |
26
|
|
|
* @see get_files_list() |
27
|
|
|
* |
28
|
|
|
* @param string $dir |
29
|
|
|
* @param bool|string $mask |
30
|
|
|
* @param string $mode |
31
|
|
|
* @param bool|string $prefix_path |
32
|
|
|
* @param bool $subfolders |
33
|
|
|
* @param bool $sort |
34
|
|
|
* @param bool|string $exclusion |
35
|
|
|
* @param bool $system_files |
36
|
|
|
* @param callable|null $apply |
37
|
|
|
* @param int|null $limit |
38
|
|
|
* |
39
|
|
|
* @return array|false |
40
|
|
|
*/ |
41
|
|
|
abstract public function get_files_list ( |
42
|
|
|
$dir, |
43
|
|
|
$mask = false, |
44
|
|
|
$mode = 'f', |
45
|
|
|
$prefix_path = false, |
46
|
|
|
$subfolders = false, |
47
|
|
|
$sort = false, |
48
|
|
|
$exclusion = false, |
49
|
|
|
$system_files = false, |
50
|
|
|
$apply = null, |
51
|
|
|
$limit = null |
52
|
|
|
); |
53
|
|
|
/** |
54
|
|
|
* Reads entire file into an array |
55
|
|
|
* |
56
|
|
|
* @abstract |
57
|
|
|
* |
58
|
|
|
* @see file() |
59
|
|
|
* |
60
|
|
|
* @param string $filename |
61
|
|
|
* @param int|null $flags |
62
|
|
|
* |
63
|
|
|
* @return array|false |
64
|
|
|
*/ |
65
|
|
|
abstract public function file ($filename, $flags = null); |
66
|
|
|
/** |
67
|
|
|
* Reads entire file into a string |
68
|
|
|
* |
69
|
|
|
* @abstract |
70
|
|
|
* |
71
|
|
|
* @see file_get_contents() |
72
|
|
|
* |
73
|
|
|
* @param string $filename |
74
|
|
|
* @param int|null $flags |
75
|
|
|
* |
76
|
|
|
* @return false|string |
77
|
|
|
*/ |
78
|
|
|
abstract public function file_get_contents ($filename, $flags = null); |
79
|
|
|
/** |
80
|
|
|
* Write a string to a file |
81
|
|
|
* |
82
|
|
|
* @abstract |
83
|
|
|
* |
84
|
|
|
* @see file_put_contents() |
85
|
|
|
* |
86
|
|
|
* @param string $filename |
87
|
|
|
* @param string $data |
88
|
|
|
* @param int|null $flags |
89
|
|
|
* |
90
|
|
|
* @return false|int |
91
|
|
|
*/ |
92
|
|
|
abstract public function file_put_contents ($filename, $data, $flags = null); |
93
|
|
|
/** |
94
|
|
|
* Copies file |
95
|
|
|
* |
96
|
|
|
* @abstract |
97
|
|
|
* |
98
|
|
|
* @see copy() |
99
|
|
|
* |
100
|
|
|
* @param string $source |
101
|
|
|
* @param string $dest |
102
|
|
|
* |
103
|
|
|
* @return bool |
104
|
|
|
*/ |
105
|
|
|
abstract public function copy ($source, $dest); |
106
|
|
|
/** |
107
|
|
|
* Deletes a file |
108
|
|
|
* |
109
|
|
|
* @abstract |
110
|
|
|
* |
111
|
|
|
* @see unlink() |
112
|
|
|
* |
113
|
|
|
* @param string $filename |
114
|
|
|
* |
115
|
|
|
* @return bool |
116
|
|
|
*/ |
117
|
|
|
abstract public function unlink ($filename); |
118
|
|
|
/** |
119
|
|
|
* Checks whether a file or directory exists |
120
|
|
|
* |
121
|
|
|
* @abstract |
122
|
|
|
* |
123
|
|
|
* @see file_exists() |
124
|
|
|
* |
125
|
|
|
* @param string $filename |
126
|
|
|
* |
127
|
|
|
* @return bool |
128
|
|
|
*/ |
129
|
|
|
abstract public function file_exists ($filename); |
130
|
|
|
/** |
131
|
|
|
* @deprecated |
132
|
|
|
* @todo Remove in 6.x |
133
|
|
|
* |
134
|
|
|
* @see static::copy() |
135
|
|
|
* |
136
|
|
|
* @param string $filename |
137
|
|
|
* @param string $destination |
138
|
|
|
* |
139
|
|
|
* @return bool |
140
|
|
|
*/ |
141
|
|
|
public function move_uploaded_file ($filename, $destination) { |
142
|
|
|
return $this->copy($filename, $destination); |
143
|
|
|
} |
144
|
|
|
/** |
145
|
|
|
* Renames a file or directory |
146
|
|
|
* |
147
|
|
|
* @abstract |
148
|
|
|
* |
149
|
|
|
* @see rename() |
150
|
|
|
* |
151
|
|
|
* @param string $oldname |
152
|
|
|
* @param string $newname |
153
|
|
|
* |
154
|
|
|
* @return bool |
155
|
|
|
*/ |
156
|
|
|
abstract public function rename ($oldname, $newname); |
157
|
|
|
/** |
158
|
|
|
* Attempts to create the directory specified by pathname. |
159
|
|
|
* |
160
|
|
|
* @abstract |
161
|
|
|
* |
162
|
|
|
* @see mkdir() |
163
|
|
|
* |
164
|
|
|
* @param string $pathname |
165
|
|
|
* @param int $mode |
166
|
|
|
* @param bool $recursive |
167
|
|
|
* |
168
|
|
|
* @return bool |
169
|
|
|
*/ |
170
|
|
|
abstract public function mkdir ($pathname, $mode = 0777, $recursive = false); |
171
|
|
|
/** |
172
|
|
|
* Removes directory |
173
|
|
|
* |
174
|
|
|
* @abstract |
175
|
|
|
* |
176
|
|
|
* @see rmdir() |
177
|
|
|
* |
178
|
|
|
* @param string $dirname |
179
|
|
|
* |
180
|
|
|
* @return bool |
181
|
|
|
*/ |
182
|
|
|
abstract public function rmdir ($dirname); |
183
|
|
|
/** |
184
|
|
|
* Tells whether the filename is a regular file |
185
|
|
|
* |
186
|
|
|
* @abstract |
187
|
|
|
* |
188
|
|
|
* @see is_file() |
189
|
|
|
* |
190
|
|
|
* @param string $filename |
191
|
|
|
* |
192
|
|
|
* @return bool |
193
|
|
|
*/ |
194
|
|
|
abstract public function is_file ($filename); |
195
|
|
|
/** |
196
|
|
|
* Tells whether the filename is a directory |
197
|
|
|
* |
198
|
|
|
* @abstract |
199
|
|
|
* |
200
|
|
|
* @see is_dir() |
201
|
|
|
* |
202
|
|
|
* @param string $filename |
203
|
|
|
* |
204
|
|
|
* @return bool |
205
|
|
|
*/ |
206
|
|
|
abstract public function is_dir ($filename); |
207
|
|
|
/** |
208
|
|
|
* Get file url by it's destination in file system |
209
|
|
|
* |
210
|
|
|
* @abstract |
211
|
|
|
* |
212
|
|
|
* @see url_by_source() |
213
|
|
|
* |
214
|
|
|
* @param string $source |
215
|
|
|
* |
216
|
|
|
* @return false|string |
217
|
|
|
*/ |
218
|
|
|
abstract public function url_by_source ($source); |
219
|
|
|
/** |
220
|
|
|
* Get file destination in file system by it's url |
221
|
|
|
* |
222
|
|
|
* @abstract |
223
|
|
|
* |
224
|
|
|
* @see source_by_url() |
225
|
|
|
* |
226
|
|
|
* @param string $url |
227
|
|
|
* |
228
|
|
|
* @return false|string |
229
|
|
|
*/ |
230
|
|
|
abstract public function source_by_url ($url); |
231
|
|
|
/** |
232
|
|
|
* Return base url of storage |
233
|
|
|
* |
234
|
|
|
* @return string |
235
|
|
|
*/ |
236
|
2 |
|
public function base_url () { |
237
|
2 |
|
return $this->base_url; |
238
|
|
|
} |
239
|
|
|
/** |
240
|
|
|
* Connection state |
241
|
|
|
* |
242
|
|
|
* @return bool |
243
|
|
|
*/ |
244
|
2 |
|
public function connected () { |
245
|
2 |
|
return $this->connected; |
246
|
|
|
} |
247
|
|
|
/** |
248
|
|
|
* Cloning restriction |
249
|
|
|
* |
250
|
|
|
* @final |
251
|
|
|
*/ |
252
|
|
|
final protected function __clone () { |
253
|
|
|
} |
254
|
|
|
} |
255
|
|
|
|
For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a
@return
doc comment to communicate to implementors of these methods what they are expected to return.