‪TYPO3CMS  10.4
AbstractHierarchicalFilesystemDriver.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
21 
26 {
34  protected function ‪isPathValid($theFile)
35  {
36  return GeneralUtility::validPathStr($theFile);
37  }
38 
46  protected function ‪canonicalizeAndCheckFilePath($filePath)
47  {
48  $filePath = ‪PathUtility::getCanonicalPath($filePath);
49 
50  // filePath must be valid
51  // Special case is required by vfsStream in Unit Test context
52  if (!$this->‪isPathValid($filePath) && strpos($filePath, 'vfs://') !== 0) {
53  throw new ‪InvalidPathException('File ' . $filePath . ' is not valid (".." and "//" is not allowed in path).', 1320286857);
54  }
55  return $filePath;
56  }
57 
65  protected function ‪canonicalizeAndCheckFileIdentifier($fileIdentifier)
66  {
67  if ($fileIdentifier !== '') {
68  $fileIdentifier = $this->‪canonicalizeAndCheckFilePath($fileIdentifier);
69  $fileIdentifier = '/' . ltrim($fileIdentifier, '/');
70  if (!$this->‪isCaseSensitiveFileSystem()) {
71  $fileIdentifier = mb_strtolower($fileIdentifier, 'utf-8');
72  }
73  }
74  return $fileIdentifier;
75  }
76 
83  protected function ‪canonicalizeAndCheckFolderIdentifier($folderPath)
84  {
85  if ($folderPath === '/') {
86  $canonicalizedIdentifier = $folderPath;
87  } else {
88  $canonicalizedIdentifier = rtrim($this->‪canonicalizeAndCheckFileIdentifier($folderPath), '/') . '/';
89  }
90  return $canonicalizedIdentifier;
91  }
92 
99  public function ‪getParentFolderIdentifierOfIdentifier($fileIdentifier)
100  {
101  $fileIdentifier = $this->‪canonicalizeAndCheckFileIdentifier($fileIdentifier);
102  return rtrim(GeneralUtility::fixWindowsFilePath(‪PathUtility::dirname($fileIdentifier)), '/') . '/';
103  }
104 }
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:24
‪TYPO3\CMS\Core\Resource\Driver\AbstractHierarchicalFilesystemDriver\canonicalizeAndCheckFilePath
‪string canonicalizeAndCheckFilePath($filePath)
Definition: AbstractHierarchicalFilesystemDriver.php:46
‪TYPO3\CMS\Core\Resource\Driver\AbstractHierarchicalFilesystemDriver\canonicalizeAndCheckFolderIdentifier
‪string canonicalizeAndCheckFolderIdentifier($folderPath)
Definition: AbstractHierarchicalFilesystemDriver.php:83
‪TYPO3\CMS\Core\Resource\Driver\AbstractHierarchicalFilesystemDriver\canonicalizeAndCheckFileIdentifier
‪string canonicalizeAndCheckFileIdentifier($fileIdentifier)
Definition: AbstractHierarchicalFilesystemDriver.php:65
‪TYPO3\CMS\Core\Utility\PathUtility\dirname
‪static string dirname($path)
Definition: PathUtility.php:186
‪TYPO3\CMS\Core\Resource\Driver\AbstractHierarchicalFilesystemDriver
Definition: AbstractHierarchicalFilesystemDriver.php:26
‪TYPO3\CMS\Core\Utility\PathUtility\getCanonicalPath
‪static string getCanonicalPath($path)
Definition: PathUtility.php:307
‪TYPO3\CMS\Core\Resource\Driver\AbstractHierarchicalFilesystemDriver\isPathValid
‪bool isPathValid($theFile)
Definition: AbstractHierarchicalFilesystemDriver.php:34
‪TYPO3\CMS\Core\Resource\Driver
Definition: AbstractDriver.php:16
‪TYPO3\CMS\Core\Resource\Driver\AbstractHierarchicalFilesystemDriver\getParentFolderIdentifierOfIdentifier
‪mixed getParentFolderIdentifierOfIdentifier($fileIdentifier)
Definition: AbstractHierarchicalFilesystemDriver.php:99
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Resource\Exception\InvalidPathException
Definition: InvalidPathException.php:24
‪TYPO3\CMS\Core\Resource\Driver\AbstractDriver
Definition: AbstractDriver.php:25
‪TYPO3\CMS\Core\Resource\Driver\AbstractDriver\isCaseSensitiveFileSystem
‪bool isCaseSensitiveFileSystem()
Definition: AbstractDriver.php:170