Files
2026-10-06 19:40:28 +02:00

41 lines
1.0 KiB
PHP

<?php
namespace HermannTelser\Zuladungsliste\Utilities;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
/**
* Class FileUtility
*/
class FileUtility extends AbstractUtility
{
/**
* @param string $path Absolute path
* @throws \Exception
*/
public static function createFolderIfNotExists(string $path)
{
if (!is_dir($path) && !GeneralUtility::mkdir($path)) {
throw new \UnexpectedValueException(
'Folder ' . self::getRelativeFolderFromAbsolutePath($path) . ' does not exists and can not be created!',
1516373962125
);
}
}
/**
* Get relative path from absolute path, but don't touch if it's already a relative path
*
* @param string $path
* @return string
*/
public static function getRelativeFolderFromAbsolutePath(string $path): string
{
if (PathUtility::isAbsolutePath($path)) {
$path = PathUtility::getRelativePathTo($path);
}
return $path;
}
}