‪TYPO3CMS  ‪main
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  // $filePath must be valid
50  if (!$this->‪isPathValid($filePath)) {
51  throw new ‪InvalidPathException('File ' . $filePath . ' is not valid (".." and "//" is not allowed in path).', 1320286857);
52  }
53  return $filePath;
54  }
55 
63  protected function ‪canonicalizeAndCheckFileIdentifier($fileIdentifier)
64  {
65  if ($fileIdentifier !== '') {
66  $fileIdentifier = $this->‪canonicalizeAndCheckFilePath($fileIdentifier);
67  $fileIdentifier = '/' . ltrim($fileIdentifier, '/');
68  if (!$this->‪isCaseSensitiveFileSystem()) {
69  $fileIdentifier = mb_strtolower($fileIdentifier, 'utf-8');
70  }
71  }
72  return $fileIdentifier;
73  }
74 
81  protected function ‪canonicalizeAndCheckFolderIdentifier($folderPath)
82  {
83  if ($folderPath === '/') {
84  $canonicalizedIdentifier = $folderPath;
85  } else {
86  $canonicalizedIdentifier = rtrim($this->‪canonicalizeAndCheckFileIdentifier($folderPath), '/') . '/';
87  }
88  return $canonicalizedIdentifier;
89  }
90 
97  public function ‪getParentFolderIdentifierOfIdentifier($fileIdentifier)
98  {
99  $fileIdentifier = $this->‪canonicalizeAndCheckFileIdentifier($fileIdentifier);
100  return rtrim(GeneralUtility::fixWindowsFilePath(‪PathUtility::dirname($fileIdentifier)), '/') . '/';
101  }
102 }
‪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\canonicalizeAndCheckFilePath
‪string canonicalizeAndCheckFilePath($filePath)
Definition: AbstractHierarchicalFilesystemDriver.php:46
‪TYPO3\CMS\Core\Resource\Driver\AbstractHierarchicalFilesystemDriver\canonicalizeAndCheckFolderIdentifier
‪string canonicalizeAndCheckFolderIdentifier($folderPath)
Definition: AbstractHierarchicalFilesystemDriver.php:81
‪TYPO3\CMS\Core\Resource\Driver\AbstractHierarchicalFilesystemDriver\canonicalizeAndCheckFileIdentifier
‪string canonicalizeAndCheckFileIdentifier($fileIdentifier)
Definition: AbstractHierarchicalFilesystemDriver.php:63
‪TYPO3\CMS\Core\Resource\Driver\AbstractHierarchicalFilesystemDriver
Definition: AbstractHierarchicalFilesystemDriver.php:26
‪TYPO3\CMS\Core\Resource\Driver\AbstractHierarchicalFilesystemDriver\isPathValid
‪bool isPathValid($theFile)
Definition: AbstractHierarchicalFilesystemDriver.php:34
‪TYPO3\CMS\Core\Utility\PathUtility\dirname
‪static dirname(string $path)
Definition: PathUtility.php:243
‪TYPO3\CMS\Core\Resource\Driver
Definition: AbstractDriver.php:16
‪TYPO3\CMS\Core\Resource\Driver\AbstractHierarchicalFilesystemDriver\getParentFolderIdentifierOfIdentifier
‪mixed getParentFolderIdentifierOfIdentifier($fileIdentifier)
Definition: AbstractHierarchicalFilesystemDriver.php:97
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪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:168