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 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 | <?php declare(encoding = 'UTF-8'); /** * xxx FAL DAM driver. * * PHP version 5 * * @category xxx * @package FAL_DAM * @subpackage Driver * @author Christian Weiske <christian.weiske@netresearch.de> */ namespace xxx\fal\dam; use \TYPO3\CMS\Core\Resource\Driver\DriverInterface; /** * Driver that caches results of another driver. * * @category xxx * @package FAL_DAM * @subpackage Driver * @author Christian Weiske <christian.weiske@netresearch.de> */ class Driver_Cache implements DriverInterface { /** * @var DriverInterface */ protected $driver; protected $fileExistsCache = array(); protected $folderExistsCache = array(); protected $getPermissionsCache = array(); public function __construct(array $configuration = array()) { $this->driver = new Driver_Dam($configuration); } /** * Checks if a file exists. * * @param string $fileIdentifier * * @return boolean */ public function fileExists($fileIdentifier) { if (!isset($this->fileExistsCache[$fileIdentifier])) { $this->fileExistsCache[$fileIdentifier] = $this->driver->fileExists($fileIdentifier); } return $this->fileExistsCache[$fileIdentifier]; } /** * Checks if a folder exists. * * @param string $folderIdentifier * * @return boolean */ public function folderExists($folderIdentifier) { if (!isset($this->folderExistsCache[$fileIdentifier])) { $this->folderExistsCache[$fileIdentifier] = $this->driver->folderExists($fileIdentifier); } return $this->folderExistsCache[$fileIdentifier]; } /** * 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) { if (!isset($this->getPermissionsCache[$fileIdentifier])) { $this->getPermissionsCache[$fileIdentifier] = $this->driver->getPermissions($identifier); } return $this->getPermissionsCache[$fileIdentifier]; } /** * Processes the configuration for this driver. * @return void */ public function processConfiguration() { $this->driver->processConfiguration(); } /** * Sets the storage uid the driver belongs to * * @param integer $storageUid * @return void */ public function setStorageUid($storageUid) { return $this->driver->setStorageUid($storageUid); } /** * Initializes this object. This is called by the storage after the driver * has been attached. * * @return void */ public function initialize() { return $this->driver->initialize(); } /** * Returns the capabilities of this driver. * * @return integer * @see Storage::CAPABILITY_* constants */ public function getCapabilities() { return $this->driver->getCapabilities(); } /** * Merges the capabilites merged by the user at the storage * configuration into the actual capabilities of the driver * and returns the result. * * @param integer $capabilities * * @return integer */ public function mergeConfigurationCapabilities($capabilities) { return $this->driver->mergeConfigurationCapabilities($capabilities); } /** * Returns TRUE if this driver has the given capability. * * @param integer $capability A capability, as defined in a CAPABILITY_* constant * @return boolean */ public function hasCapability($capability) { return $this->driver->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 boolean */ public function isCaseSensitiveFileSystem() { return $this->driver->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 = '') { return $this->driver->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) { return $this->driver->hashIdentifier($identifier); } /** * Returns the identifier of the root level folder of the storage. * * @return string */ public function getRootLevelFolder() { return $this->driver->getRootLevelFolder(); } /** * Returns the identifier of the default folder new files should be put into. * * @return string */ public function getDefaultFolder() { return $this->driver->getDefaultFolder(); } /** * Returns the identifier of the folder the file resides in * * @param string $fileIdentifier * * @return string */ public function getParentFolderIdentifierOfIdentifier($fileIdentifier) { return $this->driver->getParentFolderIdentifierOfIdentifier($fileIdentifier); } /** * Returns the public URL to a file. * Either fully qualified URL or relative to PATH_site (rawurlencoded). * * * @param string $identifier * @return string */ public function getPublicUrl($identifier) { return $this->driver->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 boolean $recursive * @return string the Identifier of the new folder */ public function createFolder($newFolderName, $parentFolderIdentifier = '', $recursive = FALSE) { return $this->driver->createFolder($newFolderName, $parentFolderIdentifier, $recursive); } /** * 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) { return $this->driver->renameFolder($folderIdentifier, $newName); } /** * Removes a folder in filesystem. * * @param string $folderIdentifier * @param boolean $deleteRecursively * @return boolean */ public function deleteFolder($folderIdentifier, $deleteRecursively = FALSE) { return $this->driver->deleteFolder($folderIdentifier, $deleteRecursively); } /** * Checks if a folder contains files and (if supported) other folders. * * @param string $folderIdentifier * @return boolean TRUE if there are no files and folders within $folder */ public function isFolderEmpty($folderIdentifier) { $this->driver->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 the original file must * not exist anymore. * * @param string $localFilePath (within PATH_site) * @param string $targetFolderIdentifier * @param string $newFileName optional, if not given original name is used * @param boolean $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) { return $this->driver->addFile($localFilePath, $targetFolderIdentifier, $newFileName, $removeOriginal); } /** * Creates a new (empty) file and returns the identifier. * * @param string $fileName * @param string $parentFolderIdentifier * @return string */ public function createFile($fileName, $parentFolderIdentifier) { return $this->driver->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) { return $this->driver->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) { return $this->driver->renameFile($fileIdentifier, $newName); } /** * Replaces a file with file in local file system. * * @param string $fileIdentifier * @param string $localFilePath * @return boolean TRUE if the operation succeeded */ public function replaceFile($fileIdentifier, $localFilePath) { return $this->driver->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 boolean TRUE if deleting the file succeeded */ public function deleteFile($fileIdentifier) { return $this->driver->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) { return $this->driver->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) { return $this->driver->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) { return $this->driver->moveFolderWithinStorage($sourceFolderIdentifier, $targetFolderIdentifier, $newFolderName); } /** * Folder equivalent to copyFileWithinStorage(). * * @param string $sourceFolderIdentifier * @param string $targetFolderIdentifier * @param string $newFolderName * * @return boolean */ public function copyFolderWithinStorage($sourceFolderIdentifier, $targetFolderIdentifier, $newFolderName) { return $this->driver->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) { return $this->driver->getFileContents($fileIdentifier); } /** * Sets the contents of a file to the specified value. * * @param string $fileIdentifier * @param string $contents * @return integer The number of bytes written to the file */ public function setFileContents($fileIdentifier, $contents) { return $this->driver->setFileContents($fileIdentifier, $contents); } /** * Checks if a file inside a folder exists * * @param string $fileName * @param string $folderIdentifier * @return boolean */ public function fileExistsInFolder($fileName, $folderIdentifier) { return $this->driver->fileExistsInFolder($fileName, $folderIdentifier); } /** * Checks if a folder inside a folder exists. * * @param string $folderName * @param string $folderIdentifier * @return boolean */ public function folderExistsInFolder($folderName, $folderIdentifier) { return $this->driver->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) { return $this->driver->getFileForLocalProcessing($fileIdentifier, $writable); } /** * 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 * @return void */ public function dumpFileContents($identifier) { return $this->driver->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 boolean TRUE if $content is within or matches $folderIdentifier */ public function isWithin($folderIdentifier, $identifier) { return $this->driver->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 = array()) { return $this->driver->getFileInfoByIdentifier($fileIdentifier, $propertiesToExtract); } /** * Returns information about a file. * * @param string $folderIdentifier * @return array */ public function getFolderInfoByIdentifier($folderIdentifier) { return $this->driver->getFolderInfoByIdentifier($folderIdentifier); } /** * Returns a list of files inside the specified path * * @param string $folderIdentifier * @param integer $start * @param integer $numberOfItems * @param boolean $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 string $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 = array(), $sort = '', $sortRev = FALSE) { return $this->driver->getFilesInFolder($folderIdentifier, $start, $numberOfItems, $recursive, $filenameFilterCallbacks, $sort, $sortRev); } /** * Returns a list of folders inside the specified path * * @param string $folderIdentifier * @param integer $start * @param integer $numberOfItems * @param boolean $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 string $sortRev TRUE to indicate reverse sorting (last to first) * * @return array of Folder Identifier */ public function getFoldersInFolder($folderIdentifier, $start = 0, $numberOfItems = 0, $recursive = FALSE, array $folderNameFilterCallbacks = array(), $sort = '', $sortRev = FALSE) { return $this->driver->getFoldersInFolder($folderIdentifier, $start, $numberOfItems, $recursive, $folderNameFilterCallbacks, $sort, $sortRev); } /** * Returns the number of files inside the specified path * * @param string $folderIdentifier * @param boolean $recursive * @param array $filenameFilterCallbacks callbacks for filtering the items * * @return integer Number of files in folder */ public function countFilesInFolder($folderIdentifier, $recursive = FALSE, array $filenameFilterCallbacks = array()) { return $this->driver->countFilesInFolder($folderIdentifier, $recursive, $filenameFilterCallbacks); } /** * Returns the number of folders inside the specified path * * @param string $folderIdentifier * @param boolean $recursive * @param array $folderNameFilterCallbacks callbacks for filtering the items * * @return integer Number of folders in folder */ public function countFoldersInFolder($folderIdentifier, $recursive = FALSE, array $folderNameFilterCallbacks = array()) { return $this->driver->countFoldersInFolder($folderIdentifier, $recursive, $folderNameFilterCallbacks); } } ?> |