- Модуль: disk
- Путь к файлу: ~/bitrix/modules/disk/lib/urlmanager.php
- Класс: BitrixDiskUrlManager
- Вызов: UrlManager::resolvePath
private function resolvePath(Storage $storage, $path, $lookUpFromFolderId, $lastPart = FolderTable::TYPE_FOLDER)
{
Diag::getInstance()->collectDebugInfo('urlmanager');
if (!is_string($path))
{
return null;
}
$path = trim($path, '/');
$relativeItems = array();
if ($path === '' && $lastPart == FileTable::TYPE)
{
return null;
}
elseif ($path === '' && $lastPart === null)
{
return array(
'STORAGE' => $storage,
'OBJECT_ID' => $lookUpFromFolderId?: $storage->getRootObjectId(),
'RELATIVE_PATH' => '/',
'RELATIVE_ITEMS' => $relativeItems,
);
}
if ( ($path === '' || $path === 'index.php') && $lastPart == FolderTable::TYPE)
{
//by default we show root folder.
return array(
'STORAGE' => $storage,
'OBJECT_ID' => $storage->getRootObjectId(),
'RELATIVE_PATH' => '/',
'RELATIVE_ITEMS' => $relativeItems,
);
}
$filter = array(
'TYPE' => FolderTable::TYPE_FOLDER,
'STORAGE_ID' => $storage->getId(),
);
if($lookUpFromFolderId !== null)
{
$filter['PARENT_ID'] = $lookUpFromFolderId;
}
$partsOfPath = explode('/', $path);
if(end($partsOfPath) == 'index.php' && $lastPart !== FileTable::TYPE)
{
array_pop($partsOfPath);
}
foreach ($partsOfPath as $i => $pieceOfPath)
{
if($i === (count($partsOfPath) - 1))
{
if($lastPart !== null)
{
$filter['TYPE'] = $lastPart;
}
else
{
unset($filter['TYPE']);
}
}
$filter['=NAME'] = $pieceOfPath;
$folder = ObjectTable::getList(array(
'filter' => $filter,
'select' => array('ID', 'NAME', 'REAL_OBJECT_ID', 'STORAGE_ID', 'PARENT_ID'),
))->fetch();
if(!$folder)
{
return null;
}
if($folder['REAL_OBJECT_ID'])
{
$filter['PARENT_ID'] = $folder['REAL_OBJECT_ID'];
unset($filter['STORAGE_ID']);
}
else
{
$filter['PARENT_ID'] = $folder['ID'];
$filter['STORAGE_ID'] = $folder['STORAGE_ID'];
}
$lookUpFromFolderId = $folder['ID'];
$relativeItems[] = array(
'ID' => $folder['ID'],
'NAME' => $pieceOfPath,
);
}
unset($pieceOfPath);
Diag::getInstance()->logDebugInfo('urlmanager');
return array(
'STORAGE' => $storage,
'OBJECT_ID' => $lookUpFromFolderId,
'RELATIVE_PATH' => implode('/', $partsOfPath),
'RELATIVE_ITEMS' => $relativeItems,
);
}