TYPO3 CMS  TYPO3_8-7
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 {
30  protected $charsetConversion;
31 
37  protected function getCharsetConversion()
38  {
39  if (!isset($this->charsetConversion)) {
40  $this->charsetConversion = GeneralUtility::makeInstance(CharsetConverter::class);
41  }
43  }
44 
52  protected function isPathValid($theFile)
53  {
54  return GeneralUtility::validPathStr($theFile);
55  }
56 
64  protected function canonicalizeAndCheckFilePath($filePath)
65  {
66  $filePath = PathUtility::getCanonicalPath($filePath);
67 
68  // filePath must be valid
69  // Special case is required by vfsStream in Unit Test context
70  if (!$this->isPathValid($filePath) && substr($filePath, 0, 6) !== 'vfs://') {
71  throw new InvalidPathException('File ' . $filePath . ' is not valid (".." and "//" is not allowed in path).', 1320286857);
72  }
73  return $filePath;
74  }
75 
83  protected function canonicalizeAndCheckFileIdentifier($fileIdentifier)
84  {
85  if ($fileIdentifier !== '') {
86  $fileIdentifier = $this->canonicalizeAndCheckFilePath($fileIdentifier);
87  $fileIdentifier = '/' . ltrim($fileIdentifier, '/');
88  if (!$this->isCaseSensitiveFileSystem()) {
89  $fileIdentifier = mb_strtolower($fileIdentifier, 'utf-8');
90  }
91  }
92  return $fileIdentifier;
93  }
94 
101  protected function canonicalizeAndCheckFolderIdentifier($folderPath)
102  {
103  if ($folderPath === '/') {
104  $canonicalizedIdentifier = $folderPath;
105  } else {
106  $canonicalizedIdentifier = rtrim($this->canonicalizeAndCheckFileIdentifier($folderPath), '/') . '/';
107  }
108  return $canonicalizedIdentifier;
109  }
110 
117  public function getParentFolderIdentifierOfIdentifier($fileIdentifier)
118  {
119  $fileIdentifier = $this->canonicalizeAndCheckFileIdentifier($fileIdentifier);
120  return rtrim(GeneralUtility::fixWindowsFilePath(PathUtility::dirname($fileIdentifier)), '/') . '/';
121  }
122 }
static makeInstance($className,... $constructorArguments)