2 namespace TYPO3\CMS\Core\
Resource\Driver
;
5 * This file is part of the TYPO3 CMS project.
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
19 * An interface Drivers have to implement to fulfil the needs
22 interface DriverInterface
{
25 * Processes the configuration for this driver.
28 public function processConfiguration();
31 * Sets the storage uid the driver belongs to
33 * @param int $storageUid
36 public function setStorageUid($storageUid);
39 * Initializes this object. This is called by the storage after the driver
44 public function initialize();
47 * Returns the capabilities of this driver.
50 * @see Storage::CAPABILITY_* constants
52 public function getCapabilities();
55 * Merges the capabilites merged by the user at the storage
56 * configuration into the actual capabilities of the driver
57 * and returns the result.
59 * @param int $capabilities
63 public function mergeConfigurationCapabilities($capabilities);
66 * Returns TRUE if this driver has the given capability.
68 * @param int $capability A capability, as defined in a CAPABILITY_* constant
71 public function hasCapability($capability);
74 * Returns TRUE if this driver uses case-sensitive identifiers. NOTE: This
75 * is a configurable setting, but the setting does not change the way the
76 * underlying file system treats the identifiers; the setting should
77 * therefore always reflect the file system and not try to change its
82 public function isCaseSensitiveFileSystem();
85 * Cleans a fileName from not allowed characters
87 * @param string $fileName
88 * @param string $charset Charset of the a fileName
89 * (defaults to current charset; depending on context)
90 * @return string the cleaned filename
92 public function sanitizeFileName($fileName, $charset = '');
95 * Hashes a file identifier, taking the case sensitivity of the file system
96 * into account. This helps mitigating problems with case-insensitive
99 * @param string $identifier
102 public function hashIdentifier($identifier);
105 * Returns the identifier of the root level folder of the storage.
109 public function getRootLevelFolder();
112 * Returns the identifier of the default folder new files should be put into.
116 public function getDefaultFolder();
119 * Returns the identifier of the folder the file resides in
121 * @param string $fileIdentifier
125 public function getParentFolderIdentifierOfIdentifier($fileIdentifier);
128 * Returns the public URL to a file.
129 * Either fully qualified URL or relative to PATH_site (rawurlencoded).
132 * @param string $identifier
135 public function getPublicUrl($identifier);
138 * Creates a folder, within a parent folder.
139 * If no parent folder is given, a root level folder will be created
141 * @param string $newFolderName
142 * @param string $parentFolderIdentifier
143 * @param bool $recursive
144 * @return string the Identifier of the new folder
146 public function createFolder($newFolderName, $parentFolderIdentifier = '', $recursive = FALSE);
149 * Renames a folder in this storage.
151 * @param string $folderIdentifier
152 * @param string $newName
153 * @return array A map of old to new file identifiers of all affected resources
155 public function renameFolder($folderIdentifier, $newName);
158 * Removes a folder in filesystem.
160 * @param string $folderIdentifier
161 * @param bool $deleteRecursively
164 public function deleteFolder($folderIdentifier, $deleteRecursively = FALSE);
167 * Checks if a file exists.
169 * @param string $fileIdentifier
173 public function fileExists($fileIdentifier);
176 * Checks if a folder exists.
178 * @param string $folderIdentifier
182 public function folderExists($folderIdentifier);
185 * Checks if a folder contains files and (if supported) other folders.
187 * @param string $folderIdentifier
188 * @return bool TRUE if there are no files and folders within $folder
190 public function isFolderEmpty($folderIdentifier);
193 * Adds a file from the local server hard disk to a given path in TYPO3s
194 * virtual file system. This assumes that the local file exists, so no
195 * further check is done here! After a successful the original file must
198 * @param string $localFilePath (within PATH_site)
199 * @param string $targetFolderIdentifier
200 * @param string $newFileName optional, if not given original name is used
201 * @param bool $removeOriginal if set the original file will be removed
202 * after successful operation
203 * @return string the identifier of the new file
205 public function addFile($localFilePath, $targetFolderIdentifier, $newFileName = '', $removeOriginal = TRUE);
208 * Creates a new (empty) file and returns the identifier.
210 * @param string $fileName
211 * @param string $parentFolderIdentifier
214 public function createFile($fileName, $parentFolderIdentifier);
217 * Copies a file *within* the current storage.
218 * Note that this is only about an inner storage copy action,
219 * where a file is just copied to another folder in the same storage.
221 * @param string $fileIdentifier
222 * @param string $targetFolderIdentifier
223 * @param string $fileName
224 * @return string the Identifier of the new file
226 public function copyFileWithinStorage($fileIdentifier, $targetFolderIdentifier, $fileName);
229 * Renames a file in this storage.
231 * @param string $fileIdentifier
232 * @param string $newName The target path (including the file name!)
233 * @return string The identifier of the file after renaming
235 public function renameFile($fileIdentifier, $newName);
238 * Replaces a file with file in local file system.
240 * @param string $fileIdentifier
241 * @param string $localFilePath
242 * @return bool TRUE if the operation succeeded
244 public function replaceFile($fileIdentifier, $localFilePath);
247 * Removes a file from the filesystem. This does not check if the file is
248 * still used or if it is a bad idea to delete it for some other reason
249 * this has to be taken care of in the upper layers (e.g. the Storage)!
251 * @param string $fileIdentifier
252 * @return bool TRUE if deleting the file succeeded
254 public function deleteFile($fileIdentifier);
257 * Creates a hash for a file.
259 * @param string $fileIdentifier
260 * @param string $hashAlgorithm The hash algorithm to use
263 public function hash($fileIdentifier, $hashAlgorithm);
267 * Moves a file *within* the current storage.
268 * Note that this is only about an inner-storage move action,
269 * where a file is just moved to another folder in the same storage.
271 * @param string $fileIdentifier
272 * @param string $targetFolderIdentifier
273 * @param string $newFileName
277 public function moveFileWithinStorage($fileIdentifier, $targetFolderIdentifier, $newFileName);
281 * Folder equivalent to moveFileWithinStorage().
283 * @param string $sourceFolderIdentifier
284 * @param string $targetFolderIdentifier
285 * @param string $newFolderName
287 * @return array All files which are affected, map of old => new file identifiers
289 public function moveFolderWithinStorage($sourceFolderIdentifier, $targetFolderIdentifier, $newFolderName);
292 * Folder equivalent to copyFileWithinStorage().
294 * @param string $sourceFolderIdentifier
295 * @param string $targetFolderIdentifier
296 * @param string $newFolderName
300 public function copyFolderWithinStorage($sourceFolderIdentifier, $targetFolderIdentifier, $newFolderName);
303 * Returns the contents of a file. Beware that this requires to load the
304 * complete file into memory and also may require fetching the file from an
305 * external location. So this might be an expensive operation (both in terms
306 * of processing resources and money) for large files.
308 * @param string $fileIdentifier
309 * @return string The file contents
311 public function getFileContents($fileIdentifier);
314 * Sets the contents of a file to the specified value.
316 * @param string $fileIdentifier
317 * @param string $contents
318 * @return int The number of bytes written to the file
320 public function setFileContents($fileIdentifier, $contents);
323 * Checks if a file inside a folder exists
325 * @param string $fileName
326 * @param string $folderIdentifier
329 public function fileExistsInFolder($fileName, $folderIdentifier);
332 * Checks if a folder inside a folder exists.
334 * @param string $folderName
335 * @param string $folderIdentifier
338 public function folderExistsInFolder($folderName, $folderIdentifier);
341 * Returns a path to a local copy of a file for processing it. When changing the
342 * file, you have to take care of replacing the current version yourself!
344 * @param string $fileIdentifier
345 * @param bool $writable Set this to FALSE if you only need the file for read
346 * operations. This might speed up things, e.g. by using
347 * a cached local version. Never modify the file if you
348 * have set this flag!
349 * @return string The path to the file on the local disk
351 public function getFileForLocalProcessing($fileIdentifier, $writable = TRUE);
354 * Returns the permissions of a file/folder as an array
355 * (keys r, w) of boolean flags
357 * @param string $identifier
360 public function getPermissions($identifier);
363 * Directly output the contents of the file to the output
364 * buffer. Should not take care of header files or flushing
365 * buffer before. Will be taken care of by the Storage.
367 * @param string $identifier
370 public function dumpFileContents($identifier);
373 * Checks if a given identifier is within a container, e.g. if
374 * a file or folder is within another folder.
375 * This can e.g. be used to check for web-mounts.
377 * Hint: this also needs to return TRUE if the given identifier
378 * matches the container identifier to allow access to the root
379 * folder of a filemount.
381 * @param string $folderIdentifier
382 * @param string $identifier identifier to be checked against $folderIdentifier
383 * @return bool TRUE if $content is within or matches $folderIdentifier
385 public function isWithin($folderIdentifier, $identifier);
388 * Returns information about a file.
390 * @param string $fileIdentifier
391 * @param array $propertiesToExtract Array of properties which are be extracted
392 * If empty all will be extracted
395 public function getFileInfoByIdentifier($fileIdentifier, array $propertiesToExtract = array());
398 * Returns information about a file.
400 * @param string $folderIdentifier
403 public function getFolderInfoByIdentifier($folderIdentifier);
406 * Returns a list of files inside the specified path
408 * @param string $folderIdentifier
410 * @param int $numberOfItems
411 * @param bool $recursive
412 * @param array $filenameFilterCallbacks callbacks for filtering the items
414 * @return array of FileIdentifiers
416 public function getFilesInFolder($folderIdentifier, $start = 0, $numberOfItems = 0, $recursive = FALSE, array $filenameFilterCallbacks = array());
419 * Returns a list of folders inside the specified path
421 * @param string $folderIdentifier
423 * @param int $numberOfItems
424 * @param bool $recursive
425 * @param array $folderNameFilterCallbacks callbacks for filtering the items
427 * @return array of Folder Identifier
429 public function getFoldersInFolder($folderIdentifier, $start = 0, $numberOfItems = 0, $recursive = FALSE, array $folderNameFilterCallbacks = array());