‪TYPO3CMS  ‪main
AbstractHierarchicalFilesystemDriver.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 
28 {
34  protected function ‪isPathValid(string $theFile): bool
35  {
36  return GeneralUtility::validPathStr($theFile);
37  }
38 
45  protected function ‪canonicalizeAndCheckFilePath(string $filePath): string
46  {
47  $filePath = ‪PathUtility::getCanonicalPath($filePath);
48  // $filePath must be valid
49  if (!$this->‪isPathValid($filePath)) {
50  throw new ‪InvalidPathException('File ' . $filePath . ' is not valid (".." and "//" is not allowed in path).', 1320286857);
51  }
52  return $filePath;
53  }
54 
61  protected function ‪canonicalizeAndCheckFileIdentifier(string $fileIdentifier): string
62  {
63  if ($fileIdentifier !== '') {
64  $fileIdentifier = $this->‪canonicalizeAndCheckFilePath($fileIdentifier);
65  $fileIdentifier = '/' . ltrim($fileIdentifier, '/');
66  if (!$this->‪isCaseSensitiveFileSystem()) {
67  $fileIdentifier = mb_strtolower($fileIdentifier, 'utf-8');
68  }
69  }
70  return $fileIdentifier;
71  }
72 
79  protected function ‪canonicalizeAndCheckFolderIdentifier(string $folderIdentifier): string
80  {
81  if ($folderIdentifier === '/') {
82  return '/';
83  }
84  return rtrim($this->‪canonicalizeAndCheckFileIdentifier($folderIdentifier), '/') . '/';
85  }
86 
93  public function ‪getParentFolderIdentifierOfIdentifier(string $fileIdentifier): string
94  {
95  $fileIdentifier = $this->‪canonicalizeAndCheckFileIdentifier($fileIdentifier);
96  return rtrim(GeneralUtility::fixWindowsFilePath(‪PathUtility::dirname($fileIdentifier)), '/') . '/';
97  }
98 }
‪TYPO3\CMS\Core\Utility\PathUtility\getCanonicalPath
‪static string getCanonicalPath(string $path)
Definition: PathUtility.php:364
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:27
‪TYPO3\CMS\Core\Resource\Driver\AbstractHierarchicalFilesystemDriver\isPathValid
‪bool isPathValid(string $theFile)
Definition: AbstractHierarchicalFilesystemDriver.php:34
‪TYPO3\CMS\Core\Resource\Driver\AbstractHierarchicalFilesystemDriver
Definition: AbstractHierarchicalFilesystemDriver.php:28
‪TYPO3\CMS\Core\Resource\Driver\AbstractHierarchicalFilesystemDriver\canonicalizeAndCheckFileIdentifier
‪canonicalizeAndCheckFileIdentifier(string $fileIdentifier)
Definition: AbstractHierarchicalFilesystemDriver.php:61
‪TYPO3\CMS\Core\Resource\Driver\AbstractHierarchicalFilesystemDriver\canonicalizeAndCheckFolderIdentifier
‪canonicalizeAndCheckFolderIdentifier(string $folderIdentifier)
Definition: AbstractHierarchicalFilesystemDriver.php:79
‪TYPO3\CMS\Core\Utility\PathUtility\dirname
‪static dirname(string $path)
Definition: PathUtility.php:243
‪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\AbstractHierarchicalFilesystemDriver\canonicalizeAndCheckFilePath
‪canonicalizeAndCheckFilePath(string $filePath)
Definition: AbstractHierarchicalFilesystemDriver.php:45
‪TYPO3\CMS\Core\Resource\Driver\AbstractHierarchicalFilesystemDriver\getParentFolderIdentifierOfIdentifier
‪getParentFolderIdentifierOfIdentifier(string $fileIdentifier)
Definition: AbstractHierarchicalFilesystemDriver.php:93
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Resource\Exception\InvalidPathException
Definition: InvalidPathException.php:23
‪TYPO3\CMS\Core\Resource\Driver\AbstractDriver
Definition: AbstractDriver.php:28