• Модуль: disk
  • Путь к файлу: ~/bitrix/modules/disk/lib/document/boxhandler.php
  • Класс: BitrixDiskDocumentBoxHandler
  • Вызов: BoxHandler::listFolder
public function listFolder($path, $folderId)
{
	if($path === '/')
	{
		$folderId = '0';
	}

	$http = new HttpClient(array(
		'socketTimeout' => 10,
		'streamTimeout' => 30,
		'version' => HttpClient::HTTP_1_1,
	));
	$http->setHeader('Content-Type', 'application/json; charset=UTF-8');
	$http->setHeader('Authorization', "Bearer {$this->getAccessToken()}");

	if($http->get(self::API_URL_V2 . "/folders/{$folderId}/items?fields=name,size,modified_at") === false)
	{
		$errorString = implode('; ', array_keys($http->getError()));
		$this->errorCollection->add(array(
			new Error($errorString, self::ERROR_HTTP_LIST_FOLDER)
		));
		return null;
	}

	if(!$this->checkHttpResponse($http))
	{
		return null;
	}

	$items = Json::decode($http->getResult());
	if($items === null)
	{
		$this->errorCollection->add(array(
			new Error('Could not decode response as json', self::ERROR_BAD_JSON)
		));
		return null;
	}
	if(!isset($items['entries']))
	{
		$this->errorCollection->add(array(
			new Error('Could not find items in response', self::ERROR_HTTP_LIST_FOLDER)
		));
		return null;
	}

	$reformatItems = array();
	foreach($items['entries'] as $item)
	{
		$isFolder = $item['type'] === 'folder';
		$dateTime = new DateTime($item['modified_at']);
		$reformatItems[$item['id']] = array(
			'id' => $item['id'],
			'name' => $item['name'],
			'type' => $isFolder? 'folder' : 'file',

			'size' => $isFolder? '' : CFile::formatSize($item['size']),
			'sizeInt' => $isFolder? '' : $item['size'],
			'modifyBy' => '',
			'modifyDate' => $dateTime->format('d.m.Y'),
			'modifyDateInt' => $dateTime->getTimestamp(),
			'provider' => static::getCode(),
		);

		if(!$isFolder)
		{
			$reformatItems[$item['id']]['storage'] = '';
			$reformatItems[$item['id']]['ext'] = getFileExtension($item['name']);
		}
	}
	unset($item);

	return $reformatItems;
}