• Модуль: dav
  • Путь к файлу: ~/bitrix/modules/dav/classes/general/webdavserver.php
  • Класс: CDavWebDavServer
  • Вызов: CDavWebDavServer::parsePath
protected function parsePath($requestUri)
{
	static $storages;

	if (empty($storages))
	{
		$cache = new CPHPCache();

		if ($cache->initCache(30*24*3600, 'webdav_disk_common_storage', '/webdav/storage'))
		{
			$storages = $cache->getVars();
		}
		else
		{
			$storages = BitrixDiskStorage::getModelList(array(
				'filter' => array(
					'=ENTITY_TYPE' => BitrixDiskProxyTypeCommon::className(),
				)
			));

			foreach ($storages as $key => $storage)
			{
				$storages[$key] = array(
					'id'   => $storage->getEntityId(),
					'path' => $storage->getProxyType()->getStorageBaseUrl()
				);
			}

			$cache->startDataCache();

			if (defined('BX_COMP_MANAGED_CACHE'))
			{
				$taggedCache = BitrixMainApplication::getInstance()->getTaggedCache();

				$taggedCache->startTagCache('/webdav/storage');
				$taggedCache->registerTag('disk_common_storage');
				$taggedCache->endTagCache();
			}

			$cache->endDataCache($storages);
		}
	}

	$patterns = array(
		array('user', '/(?:company|contacts)/personal/user/(d+)/files/lib(.*)$'),
		array('user', '/(?:company|contacts)/personal/user/(d+)/disk/path(.*)$'),
		array('group', '/workgroups/group/(\d+)/files(.*)$'),
		array('group', '/workgroups/group/(\d+)/disk/path(.*)$'),
	);

	foreach ($storages as $storage)
	{
		$storagePath = trim($storage['path'], '/');

		$patterns[] = array('docs', sprintf('^/%s/path(.*)$', $storagePath), $storage['id']);
		$patterns[] = array('docs', sprintf('^/%s/(.*)$', $storagePath), $storage['id']);
	}

	// @TODO: aggregator
	$patterns[] = array('all', '^(/docs/path/[^/]+)(/.*)', 'all');
	$patterns[] = array('all', '^(/docs/'.$this->titleGroupStoragesQuote.'/[^/]+)(/.*)', 'all');
	$patterns[] = array('all', '^(/docs/'.$this->titleUserStoragesQuote.'/[^/]+)(/.*)', 'all');
	$patterns[] = array('all', '^(/docs/[^/]+)(/.*)', 'all');

	$type = null;
	$id   = null;
	$path = null;
	foreach ($patterns as $pattern)
	{
		$matches = array();
		if (preg_match('#'.$pattern[1].'#i', $requestUri, $matches))
		{
			$type = $pattern[0];
			if ($type === 'all')
			{
				$storage = null;
				$storageId = $this->getStorageId($matches[1]);
				$storage = Storage::loadById($storageId);

				if (!$storage)
				{
					return [null, null];
				}

				$id = $storage->getEntityId();
				$path = $matches[2];
				$type = $this->getEntityType($storage);

				break;
			}

			list($id, $path) = ($type === 'docs')
				? array($pattern[2], $matches[1])
				: array($matches[1], $matches[2]);
			break;
		}
	}
	/** @var Storage $storage */

	$storage = null;
	if ($type === 'user')
	{
		$storage = Driver::getInstance()->getStorageByUserId((int)$id);
	}
	elseif ($type === 'group')
	{
		$storage = Driver::getInstance()->getStorageByGroupId((int)$id);
	}
	elseif ($type === 'docs' || $type === 'common')
	{
		$storage = Driver::getInstance()->getStorageByCommonId($id);
	}
	else
	{
		return [null, null];
	}

	$path = $path ?: '/';
	$path = static::UrlDecode($path);

	return array($storage, $path);
}