‪TYPO3CMS  ‪main
AbstractDriver.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
23 
27 abstract class ‪AbstractDriver implements DriverInterface
28 {
29  /*******************
30  * CAPABILITIES
31  *******************/
36 
40  protected ?int ‪$storageUid = null;
41 
54  protected array ‪$supportedHashAlgorithms = [];
55 
59  protected array ‪$configuration = [];
60 
64  public function ‪__construct(array ‪$configuration = [])
65  {
66  $this->configuration = ‪$configuration;
67  }
68 
73  protected function ‪isValidFilename(string $fileName): bool
74  {
75  if (str_contains($fileName, '/')) {
76  return false;
77  }
78  if (!preg_match('/^[\\pL\\d[:blank:]._-]*$/u', $fileName)) {
79  return false;
80  }
81  return true;
82  }
83 
87  public function ‪setStorageUid(int ‪$storageUid): void
88  {
89  $this->storageUid = ‪$storageUid;
90  }
91 
96  {
98  }
99 
105  public function ‪hasCapability(int $capability): bool
106  {
107  return $this->‪getCapabilities()->hasCapability($capability);
108  }
109 
110  /*******************
111  * FILE FUNCTIONS
112  *******************/
113 
120  protected function ‪getTemporaryPathForFile(string $fileIdentifier): string
121  {
122  return GeneralUtility::tempnam('fal-tempfile-', '.' . ‪PathUtility::pathinfo($fileIdentifier, PATHINFO_EXTENSION));
123  }
124 
133  public function ‪hashIdentifier(string ‪$identifier): string
134  {
136  return sha1(‪$identifier);
137  }
138 
146  public function ‪isCaseSensitiveFileSystem(): bool
147  {
148  if (isset($this->configuration['caseSensitive'])) {
149  return (bool)$this->configuration['caseSensitive'];
150  }
151  return true;
152  }
153 
160  abstract protected function ‪canonicalizeAndCheckFilePath(string $filePath): string;
161 
168  abstract protected function ‪canonicalizeAndCheckFileIdentifier(string $fileIdentifier): string;
169 
176  abstract protected function ‪canonicalizeAndCheckFolderIdentifier(string $folderIdentifier): string;
177 }
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:27
‪TYPO3\CMS\Core\Resource\Driver\AbstractDriver\$configuration
‪array $configuration
Definition: AbstractDriver.php:59
‪TYPO3\CMS\Core\Resource\Capabilities
Definition: Capabilities.php:23
‪TYPO3\CMS\Core\Resource\Driver\AbstractDriver\canonicalizeAndCheckFolderIdentifier
‪canonicalizeAndCheckFolderIdentifier(string $folderIdentifier)
‪TYPO3\CMS\Core\Resource\Driver\AbstractDriver\setStorageUid
‪setStorageUid(int $storageUid)
Definition: AbstractDriver.php:87
‪TYPO3\CMS\Core\Resource\Driver\AbstractDriver\$capabilities
‪Capabilities $capabilities
Definition: AbstractDriver.php:35
‪TYPO3\CMS\Core\Resource\Driver\AbstractDriver\hasCapability
‪hasCapability(int $capability)
Definition: AbstractDriver.php:105
‪TYPO3\CMS\Core\Resource\Driver\AbstractDriver\isValidFilename
‪isValidFilename(string $fileName)
Definition: AbstractDriver.php:73
‪TYPO3\CMS\Core\Resource\Driver\AbstractDriver\$supportedHashAlgorithms
‪array $supportedHashAlgorithms
Definition: AbstractDriver.php:54
‪TYPO3\CMS\Core\Resource\Driver
Definition: AbstractDriver.php:18
‪TYPO3\CMS\Core\Resource\Driver\AbstractDriver\isCaseSensitiveFileSystem
‪isCaseSensitiveFileSystem()
Definition: AbstractDriver.php:146
‪TYPO3\CMS\Core\Resource\Driver\AbstractDriver\canonicalizeAndCheckFilePath
‪canonicalizeAndCheckFilePath(string $filePath)
‪TYPO3\CMS\Core\Resource\Driver\AbstractDriver\$storageUid
‪int $storageUid
Definition: AbstractDriver.php:40
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Resource\Driver\AbstractDriver\__construct
‪__construct(array $configuration=[])
Definition: AbstractDriver.php:64
‪TYPO3\CMS\Core\Resource\Driver\AbstractDriver\canonicalizeAndCheckFileIdentifier
‪canonicalizeAndCheckFileIdentifier(string $fileIdentifier)
‪TYPO3\CMS\Core\Resource\Driver\AbstractDriver\getTemporaryPathForFile
‪getTemporaryPathForFile(string $fileIdentifier)
Definition: AbstractDriver.php:120
‪TYPO3\CMS\Core\Resource\Driver\AbstractDriver\hashIdentifier
‪hashIdentifier(string $identifier)
Definition: AbstractDriver.php:133
‪TYPO3\CMS\Core\Utility\PathUtility\pathinfo
‪static string string[] pathinfo(string $path, int $options=PATHINFO_ALL)
Definition: PathUtility.php:270
‪TYPO3\CMS\Webhooks\Message\$identifier
‪identifier readonly string $identifier
Definition: FileAddedMessage.php:37
‪TYPO3\CMS\Core\Resource\Driver\AbstractDriver
Definition: AbstractDriver.php:28
‪TYPO3\CMS\Core\Resource\Driver\AbstractDriver\getCapabilities
‪getCapabilities()
Definition: AbstractDriver.php:95