- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/classes/general/virtual_io_filesystem.php
- Класс: CBXVirtualIoFileSystem
- Вызов: CBXVirtualIoFileSystem::FormatPath
private function FormatPath($path)
{
if ($path == "")
return null;
//slashes doesn't matter for Windows
if(strncasecmp(PHP_OS, "WIN", 3) == 0)
{
//windows
$pattern = "'[\\/]+'";
$tailPattern = " .\/+ ";
}
else
{
//unix
$pattern = "'[/]+'";
$tailPattern = " /";
}
$res = preg_replace($pattern, "/", $path);
if (strpos($res, " ") !== false)
throw new BitrixMainIOInvalidPathException($path);
$arPath = explode('/', $res);
$nPath = count($arPath);
$pathStack = array();
for ($i = 0; $i < $nPath; $i++)
{
if ($arPath[$i] === ".")
continue;
if (($arPath[$i] === '') && ($i !== ($nPath - 1)) && ($i !== 0))
continue;
if ($arPath[$i] === "..")
array_pop($pathStack);
else
array_push($pathStack, $arPath[$i]);
}
$res = implode("/", $pathStack);
$res = rtrim($res, $tailPattern);
if(mb_substr($path, 0, 1) === "/" && mb_substr($res, 0, 1) !== "/")
$res = "/".$res;
if ($res === "")
$res = "/";
return $res;
}