‪TYPO3CMS  9.5
AbstractHierarchicalFilesystemDriver.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
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.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 
26 {
31  protected ‪$charsetConversion;
32 
39  protected function ‪getCharsetConversion()
40  {
41  trigger_error('Shorthand method "getCharsetConversion()" within the FAL driver method will be removed in TYPO3 v10.0, instantiate CharsetConverter yourself.', E_USER_DEPRECATED);
42  if (!isset($this->charsetConversion)) {
43  $this->charsetConversion = GeneralUtility::makeInstance(CharsetConverter::class);
44  }
46  }
47 
55  protected function ‪isPathValid($theFile)
56  {
57  return GeneralUtility::validPathStr($theFile);
58  }
59 
67  protected function ‪canonicalizeAndCheckFilePath($filePath)
68  {
69  $filePath = ‪PathUtility::getCanonicalPath($filePath);
70 
71  // filePath must be valid
72  // Special case is required by vfsStream in Unit Test context
73  if (!$this->‪isPathValid($filePath) && strpos($filePath, 'vfs://') !== 0) {
74  throw new ‪InvalidPathException('File ' . $filePath . ' is not valid (".." and "//" is not allowed in path).', 1320286857);
75  }
76  return $filePath;
77  }
78 
86  protected function ‪canonicalizeAndCheckFileIdentifier($fileIdentifier)
87  {
88  if ($fileIdentifier !== '') {
89  $fileIdentifier = $this->‪canonicalizeAndCheckFilePath($fileIdentifier);
90  $fileIdentifier = '/' . ltrim($fileIdentifier, '/');
91  if (!$this->‪isCaseSensitiveFileSystem()) {
92  $fileIdentifier = mb_strtolower($fileIdentifier, 'utf-8');
93  }
94  }
95  return $fileIdentifier;
96  }
97 
104  protected function ‪canonicalizeAndCheckFolderIdentifier($folderPath)
105  {
106  if ($folderPath === '/') {
107  $canonicalizedIdentifier = $folderPath;
108  } else {
109  $canonicalizedIdentifier = rtrim($this->‪canonicalizeAndCheckFileIdentifier($folderPath), '/') . '/';
110  }
111  return $canonicalizedIdentifier;
112  }
113 
120  public function ‪getParentFolderIdentifierOfIdentifier($fileIdentifier)
121  {
122  $fileIdentifier = $this->‪canonicalizeAndCheckFileIdentifier($fileIdentifier);
123  return rtrim(GeneralUtility::fixWindowsFilePath(‪PathUtility::dirname($fileIdentifier)), '/') . '/';
124  }
125 }
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:23
‪TYPO3\CMS\Core\Resource\Driver\AbstractHierarchicalFilesystemDriver\canonicalizeAndCheckFilePath
‪string canonicalizeAndCheckFilePath($filePath)
Definition: AbstractHierarchicalFilesystemDriver.php:66
‪TYPO3\CMS\Core\Resource\Driver\AbstractHierarchicalFilesystemDriver\canonicalizeAndCheckFolderIdentifier
‪string canonicalizeAndCheckFolderIdentifier($folderPath)
Definition: AbstractHierarchicalFilesystemDriver.php:103
‪TYPO3\CMS\Core\Resource\Driver\AbstractHierarchicalFilesystemDriver\canonicalizeAndCheckFileIdentifier
‪string canonicalizeAndCheckFileIdentifier($fileIdentifier)
Definition: AbstractHierarchicalFilesystemDriver.php:85
‪TYPO3\CMS\Core\Resource\Driver\AbstractHierarchicalFilesystemDriver\getCharsetConversion
‪CharsetConverter getCharsetConversion()
Definition: AbstractHierarchicalFilesystemDriver.php:38
‪TYPO3\CMS\Core\Utility\PathUtility\dirname
‪static string dirname($path)
Definition: PathUtility.php:185
‪TYPO3\CMS\Core\Resource\Driver\AbstractHierarchicalFilesystemDriver
Definition: AbstractHierarchicalFilesystemDriver.php:26
‪TYPO3\CMS\Core\Charset\CharsetConverter
Definition: CharsetConverter.php:54
‪TYPO3\CMS\Core\Utility\PathUtility\getCanonicalPath
‪static string getCanonicalPath($path)
Definition: PathUtility.php:306
‪TYPO3\CMS\Core\Resource\Driver\AbstractHierarchicalFilesystemDriver\$charsetConversion
‪CharsetConverter $charsetConversion
Definition: AbstractHierarchicalFilesystemDriver.php:30
‪TYPO3\CMS\Core\Resource\Driver\AbstractHierarchicalFilesystemDriver\isPathValid
‪bool isPathValid($theFile)
Definition: AbstractHierarchicalFilesystemDriver.php:54
‪TYPO3\CMS\Core\Resource\Driver
Definition: AbstractDriver.php:2
‪TYPO3\CMS\Core\Resource\Driver\AbstractHierarchicalFilesystemDriver\getParentFolderIdentifierOfIdentifier
‪mixed getParentFolderIdentifierOfIdentifier($fileIdentifier)
Definition: AbstractHierarchicalFilesystemDriver.php:119
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Resource\Exception\InvalidPathException
Definition: InvalidPathException.php:21
‪TYPO3\CMS\Core\Resource\Driver\AbstractDriver
Definition: AbstractDriver.php:23
‪TYPO3\CMS\Core\Resource\Driver\AbstractDriver\isCaseSensitiveFileSystem
‪bool isCaseSensitiveFileSystem()
Definition: AbstractDriver.php:165