isPathValid($filePath)) { throw new InvalidPathException('File ' . $filePath . ' is not valid (".." and "//" is not allowed in path).', 1320286857); } return $filePath; } /** * Makes sure the Path given as parameter is valid. * * @param string $fileIdentifier The file path (including the file name!) */ protected function canonicalizeAndCheckFileIdentifier(string $fileIdentifier): string { if ($fileIdentifier !== '') { $fileIdentifier = $this->canonicalizeAndCheckFilePath($fileIdentifier); $fileIdentifier = '/' . ltrim($fileIdentifier, '/'); if (!$this->isCaseSensitiveFileSystem()) { $fileIdentifier = mb_strtolower($fileIdentifier, 'utf-8'); } } return $fileIdentifier; } /** * Makes sure the Path given as parameter is valid. * * @phpstan-param non-empty-string $folderIdentifier The file path (including the file name!) * @phpstan-return non-empty-string */ protected function canonicalizeAndCheckFolderIdentifier(string $folderIdentifier): string { if ($folderIdentifier === '/') { return '/'; } return rtrim($this->canonicalizeAndCheckFileIdentifier($folderIdentifier), '/') . '/'; } /** * Returns the identifier of the folder the file resides in. * * @phpstan-param non-empty-string $fileIdentifier * @phpstan-return non-empty-string */ public function getParentFolderIdentifierOfIdentifier(string $fileIdentifier): string { $fileIdentifier = $this->canonicalizeAndCheckFileIdentifier($fileIdentifier); return rtrim(GeneralUtility::fixWindowsFilePath(PathUtility::dirname($fileIdentifier)), '/') . '/'; } }