TYPO3 CMS  TYPO3_7-6
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 {
29  protected function isPathValid($theFile)
30  {
31  return \TYPO3\CMS\Core\Utility\GeneralUtility::validPathStr($theFile);
32  }
33 
41  protected function canonicalizeAndCheckFilePath($filePath)
42  {
44 
45  // filePath must be valid
46  // Special case is required by vfsStream in Unit Test context
47  if (!$this->isPathValid($filePath) && substr($filePath, 0, 6) !== 'vfs://') {
48  throw new \TYPO3\CMS\Core\Resource\Exception\InvalidPathException('File ' . $filePath . ' is not valid (".." and "//" is not allowed in path).', 1320286857);
49  }
50  return $filePath;
51  }
52 
60  protected function canonicalizeAndCheckFileIdentifier($fileIdentifier)
61  {
62  if ($fileIdentifier !== '') {
63  $fileIdentifier = $this->canonicalizeAndCheckFilePath($fileIdentifier);
64  $fileIdentifier = '/' . ltrim($fileIdentifier, '/');
65  if (!$this->isCaseSensitiveFileSystem()) {
66  $fileIdentifier = strtolower($fileIdentifier);
67  }
68  }
69  return $fileIdentifier;
70  }
71 
78  protected function canonicalizeAndCheckFolderIdentifier($folderPath)
79  {
80  if ($folderPath === '/') {
81  $canonicalizedIdentifier = $folderPath;
82  } else {
83  $canonicalizedIdentifier = rtrim($this->canonicalizeAndCheckFileIdentifier($folderPath), '/') . '/';
84  }
85  return $canonicalizedIdentifier;
86  }
87 
94  public function getParentFolderIdentifierOfIdentifier($fileIdentifier)
95  {
96  $fileIdentifier = $this->canonicalizeAndCheckFileIdentifier($fileIdentifier);
97  return \TYPO3\CMS\Core\Utility\PathUtility::dirname($fileIdentifier) . '/';
98  }
99 }