-
Notifications
You must be signed in to change notification settings - Fork 18
/
DriverInterface.php
464 lines (417 loc) · 15.6 KB
/
DriverInterface.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Resource\Driver;
/**
* An interface Drivers have to implement to fulfil the needs
* of the FAL API.
*/
interface DriverInterface
{
/**
* Processes the configuration for this driver.
*/
public function processConfiguration();
/**
* Sets the storage uid the driver belongs to
*
* @param int $storageUid
*/
public function setStorageUid($storageUid);
/**
* Initializes this object. This is called by the storage after the driver
* has been attached.
*/
public function initialize();
/**
* Returns the capabilities of this driver.
*
* @return int
* @see ResourceStorageInterface::CAPABILITY_ constants
*/
public function getCapabilities();
/**
* Merges the capabilities merged by the user at the storage
* configuration into the actual capabilities of the driver
* and returns the result.
*
* @param int $capabilities
* @return int
*/
public function mergeConfigurationCapabilities($capabilities);
/**
* Returns TRUE if this driver has the given capability.
*
* @param int $capability A capability, as defined in a CAPABILITY_* constant
* @return bool
*/
public function hasCapability($capability);
/**
* Returns TRUE if this driver uses case-sensitive identifiers. NOTE: This
* is a configurable setting, but the setting does not change the way the
* underlying file system treats the identifiers; the setting should
* therefore always reflect the file system and not try to change its
* behaviour
*
* @return bool
*/
public function isCaseSensitiveFileSystem();
/**
* Cleans a fileName from not allowed characters
*
* @param string $fileName
* @param string $charset Charset of the a fileName
* (defaults to current charset; depending on context)
* @return string the cleaned filename
*/
public function sanitizeFileName($fileName, $charset = '');
/**
* Hashes a file identifier, taking the case sensitivity of the file system
* into account. This helps mitigating problems with case-insensitive
* databases.
*
* @param string $identifier
* @return string
*/
public function hashIdentifier($identifier);
/**
* Returns the identifier of the root level folder of the storage.
*
* @return string
*/
public function getRootLevelFolder();
/**
* Returns the identifier of the default folder new files should be put into.
*
* @return string
*/
public function getDefaultFolder();
/**
* Returns the identifier of the folder the file resides in
*
* @param string $fileIdentifier
* @return string
*/
public function getParentFolderIdentifierOfIdentifier($fileIdentifier);
/**
* Returns the public URL to a file.
* Either fully qualified URL or relative to public web path (rawurlencoded).
*
* @param string $identifier
* @return string|null NULL if file is missing or deleted, the generated url otherwise
*/
public function getPublicUrl($identifier);
/**
* Creates a folder, within a parent folder.
* If no parent folder is given, a root level folder will be created
*
* @param string $newFolderName
* @param string $parentFolderIdentifier
* @param bool $recursive
* @return string the Identifier of the new folder
*/
public function createFolder($newFolderName, $parentFolderIdentifier = '', $recursive = false);
/**
* Renames a folder in this storage.
*
* @param string $folderIdentifier
* @param string $newName
* @return array A map of old to new file identifiers of all affected resources
*/
public function renameFolder($folderIdentifier, $newName);
/**
* Removes a folder in filesystem.
*
* @param string $folderIdentifier
* @param bool $deleteRecursively
* @return bool
*/
public function deleteFolder($folderIdentifier, $deleteRecursively = false);
/**
* Checks if a file exists.
*
* @param string $fileIdentifier
* @return bool
*/
public function fileExists($fileIdentifier);
/**
* Checks if a folder exists.
*
* @param string $folderIdentifier
* @return bool
*/
public function folderExists($folderIdentifier);
/**
* Checks if a folder contains files and (if supported) other folders.
*
* @param string $folderIdentifier
* @return bool TRUE if there are no files and folders within $folder
*/
public function isFolderEmpty($folderIdentifier);
/**
* Adds a file from the local server hard disk to a given path in TYPO3s
* virtual file system. This assumes that the local file exists, so no
* further check is done here! After a successful operation the original
* file must not exist anymore.
*
* @param string $localFilePath within public web path
* @param string $targetFolderIdentifier
* @param string $newFileName optional, if not given original name is used
* @param bool $removeOriginal if set the original file will be removed
* after successful operation
* @return string the identifier of the new file
*/
public function addFile($localFilePath, $targetFolderIdentifier, $newFileName = '', $removeOriginal = true);
/**
* Creates a new (empty) file and returns the identifier.
*
* @param string $fileName
* @param string $parentFolderIdentifier
* @return string
*/
public function createFile($fileName, $parentFolderIdentifier);
/**
* Copies a file *within* the current storage.
* Note that this is only about an inner storage copy action,
* where a file is just copied to another folder in the same storage.
*
* @param string $fileIdentifier
* @param string $targetFolderIdentifier
* @param string $fileName
* @return string the Identifier of the new file
*/
public function copyFileWithinStorage($fileIdentifier, $targetFolderIdentifier, $fileName);
/**
* Renames a file in this storage.
*
* @param string $fileIdentifier
* @param string $newName The target path (including the file name!)
* @return string The identifier of the file after renaming
*/
public function renameFile($fileIdentifier, $newName);
/**
* Replaces a file with file in local file system.
*
* @param string $fileIdentifier
* @param string $localFilePath
* @return bool TRUE if the operation succeeded
*/
public function replaceFile($fileIdentifier, $localFilePath);
/**
* Removes a file from the filesystem. This does not check if the file is
* still used or if it is a bad idea to delete it for some other reason
* this has to be taken care of in the upper layers (e.g. the Storage)!
*
* @param string $fileIdentifier
* @return bool TRUE if deleting the file succeeded
*/
public function deleteFile($fileIdentifier);
/**
* Creates a hash for a file.
*
* @param string $fileIdentifier
* @param string $hashAlgorithm The hash algorithm to use
* @return string
*/
public function hash($fileIdentifier, $hashAlgorithm);
/**
* Moves a file *within* the current storage.
* Note that this is only about an inner-storage move action,
* where a file is just moved to another folder in the same storage.
*
* @param string $fileIdentifier
* @param string $targetFolderIdentifier
* @param string $newFileName
* @return string
*/
public function moveFileWithinStorage($fileIdentifier, $targetFolderIdentifier, $newFileName);
/**
* Folder equivalent to moveFileWithinStorage().
*
* @param string $sourceFolderIdentifier
* @param string $targetFolderIdentifier
* @param string $newFolderName
* @return array All files which are affected, map of old => new file identifiers
*/
public function moveFolderWithinStorage($sourceFolderIdentifier, $targetFolderIdentifier, $newFolderName);
/**
* Folder equivalent to copyFileWithinStorage().
*
* @param string $sourceFolderIdentifier
* @param string $targetFolderIdentifier
* @param string $newFolderName
* @return bool
*/
public function copyFolderWithinStorage($sourceFolderIdentifier, $targetFolderIdentifier, $newFolderName);
/**
* Returns the contents of a file. Beware that this requires to load the
* complete file into memory and also may require fetching the file from an
* external location. So this might be an expensive operation (both in terms
* of processing resources and money) for large files.
*
* @param string $fileIdentifier
* @return string The file contents
*/
public function getFileContents($fileIdentifier);
/**
* Sets the contents of a file to the specified value.
*
* @param string $fileIdentifier
* @param string $contents
* @return int The number of bytes written to the file
*/
public function setFileContents($fileIdentifier, $contents);
/**
* Checks if a file inside a folder exists
*
* @param string $fileName
* @param string $folderIdentifier
* @return bool
*/
public function fileExistsInFolder($fileName, $folderIdentifier);
/**
* Checks if a folder inside a folder exists.
*
* @param string $folderName
* @param string $folderIdentifier
* @return bool
*/
public function folderExistsInFolder($folderName, $folderIdentifier);
/**
* Returns a path to a local copy of a file for processing it. When changing the
* file, you have to take care of replacing the current version yourself!
*
* @param string $fileIdentifier
* @param bool $writable Set this to FALSE if you only need the file for read
* operations. This might speed up things, e.g. by using
* a cached local version. Never modify the file if you
* have set this flag!
* @return string The path to the file on the local disk
*/
public function getFileForLocalProcessing($fileIdentifier, $writable = true);
/**
* Returns the permissions of a file/folder as an array
* (keys r, w) of boolean flags
*
* @param string $identifier
* @return array
*/
public function getPermissions($identifier);
/**
* Directly output the contents of the file to the output
* buffer. Should not take care of header files or flushing
* buffer before. Will be taken care of by the Storage.
*
* @param string $identifier
*/
public function dumpFileContents($identifier);
/**
* Checks if a given identifier is within a container, e.g. if
* a file or folder is within another folder.
* This can e.g. be used to check for web-mounts.
*
* Hint: this also needs to return TRUE if the given identifier
* matches the container identifier to allow access to the root
* folder of a filemount.
*
* @param string $folderIdentifier
* @param string $identifier identifier to be checked against $folderIdentifier
* @return bool TRUE if $content is within or matches $folderIdentifier
*/
public function isWithin($folderIdentifier, $identifier);
/**
* Returns information about a file.
*
* @param string $fileIdentifier
* @param array $propertiesToExtract Array of properties which are be extracted
* If empty all will be extracted
* @return array
*/
public function getFileInfoByIdentifier($fileIdentifier, array $propertiesToExtract = []);
/**
* Returns information about a file.
*
* @param string $folderIdentifier
* @return array
*/
public function getFolderInfoByIdentifier($folderIdentifier);
/**
* Returns the identifier of a file inside the folder
*
* @param string $fileName
* @param string $folderIdentifier
* @return string file identifier
*/
public function getFileInFolder($fileName, $folderIdentifier);
/**
* Returns a list of files inside the specified path
*
* @param string $folderIdentifier
* @param int $start
* @param int $numberOfItems
* @param bool $recursive
* @param array $filenameFilterCallbacks callbacks for filtering the items
* @param string $sort Property name used to sort the items.
* Among them may be: '' (empty, no sorting), name,
* fileext, size, tstamp and rw.
* If a driver does not support the given property, it
* should fall back to "name".
* @param bool $sortRev TRUE to indicate reverse sorting (last to first)
* @return array of FileIdentifiers
*/
public function getFilesInFolder($folderIdentifier, $start = 0, $numberOfItems = 0, $recursive = false, array $filenameFilterCallbacks = [], $sort = '', $sortRev = false);
/**
* Returns the identifier of a folder inside the folder
*
* @param string $folderName The name of the target folder
* @param string $folderIdentifier
* @return string folder identifier
*/
public function getFolderInFolder($folderName, $folderIdentifier);
/**
* Returns a list of folders inside the specified path
*
* @param string $folderIdentifier
* @param int $start
* @param int $numberOfItems
* @param bool $recursive
* @param array $folderNameFilterCallbacks callbacks for filtering the items
* @param string $sort Property name used to sort the items.
* Among them may be: '' (empty, no sorting), name,
* fileext, size, tstamp and rw.
* If a driver does not support the given property, it
* should fall back to "name".
* @param bool $sortRev TRUE to indicate reverse sorting (last to first)
* @return array<string|int, string> folder identifiers (where key and value are identical, but int-like identifiers
* will get converted to int array keys)
*/
public function getFoldersInFolder($folderIdentifier, $start = 0, $numberOfItems = 0, $recursive = false, array $folderNameFilterCallbacks = [], $sort = '', $sortRev = false);
/**
* Returns the number of files inside the specified path
*
* @param string $folderIdentifier
* @param bool $recursive
* @param array $filenameFilterCallbacks callbacks for filtering the items
* @return int Number of files in folder
*/
public function countFilesInFolder($folderIdentifier, $recursive = false, array $filenameFilterCallbacks = []);
/**
* Returns the number of folders inside the specified path
*
* @param string $folderIdentifier
* @param bool $recursive
* @param array $folderNameFilterCallbacks callbacks for filtering the items
* @return int Number of folders in folder
*/
public function countFoldersInFolder($folderIdentifier, $recursive = false, array $folderNameFilterCallbacks = []);
}