- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/lib/io/path.php
- Класс: BitrixMainIOPath
- Вызов: Path::normalize
static function normalize($path)
{
if (!is_string($path) || ($path == ""))
return null;
//slashes doesn't matter for Windows
static $pattern = null, $tailPattern;
if (!$pattern)
{
if(strncasecmp(PHP_OS, "WIN", 3) == 0)
{
//windows
$pattern = "'[\\/]+'";
$tailPattern = " .\/+ ";
}
else
{
//unix
$pattern = "'[/]+'";
$tailPattern = " /";
}
}
$pathTmp = preg_replace($pattern, "/", $path);
if (strpos($pathTmp, " ") !== false)
throw new InvalidPathException($path);
if (preg_match("#(^|/)(\.|\.\.)(/|$)#", $pathTmp))
{
$arPathTmp = explode('/', $pathTmp);
$arPathStack = array();
foreach ($arPathTmp as $i => $pathPart)
{
if ($pathPart === '.')
continue;
if ($pathPart === "..")
{
if (array_pop($arPathStack) === null)
throw new InvalidPathException($path);
}
else
{
array_push($arPathStack, $pathPart);
}
}
$pathTmp = implode("/", $arPathStack);
}
$pathTmp = rtrim($pathTmp, $tailPattern);
if (mb_substr($path, 0, 1) === "/" && mb_substr($pathTmp, 0, 1) !== "/")
$pathTmp = "/".$pathTmp;
if ($pathTmp === '')
$pathTmp = "/";
return $pathTmp;
}