- Модуль: rest
- Путь к файлу: ~/bitrix/modules/rest/lib/engine/restmanager.php
- Класс: BitrixRestEngineRestManager
- Вызов: RestManager::processMethodRequest
public function processMethodRequest(array $params, $start, CRestServer $restServer)
{
$start = intval($start);
$this->initialize($restServer, $start);
$errorCollection = new ErrorCollection();
$method = $restServer->getMethod();
$methodData = ScopeManager::getInstance()->getMethodInfo($method);
$request = new BitrixMainHttpRequest(
Context::getCurrent()->getServer(),
['action' => $methodData['method']],
[], [], []
);
$router = new EngineRouter($request);
/** @var Controller $controller */
[$controller, $action] = Resolver::getControllerAndAction(
$router->getVendor(),
$router->getModule(),
$router->getAction(),
Controller::SCOPE_REST
);
if (!$controller)
{
throw new RestException("Unknown {$method}. There is not controller in module {$router->getModule()}");
}
$this->calculateTotalCount = true;
if ((int)$start === self::DONT_CALCULATE_COUNT)
{
$this->calculateTotalCount = false;
}
$autoWirings = $this->getAutoWirings();
$this->registerAutoWirings($autoWirings);
$result = $controller->run($action, [$params, ['__restServer' => $restServer, '__calculateTotalCount' => $this->calculateTotalCount]]);
$this->unRegisterAutoWirings($autoWirings);
if ($result instanceof EngineResponseFile)
{
return $result->send();
}
if ($result instanceof HttpResponse)
{
if ($result instanceof Errorable)
{
$errorCollection->add($result->getErrors());
}
$result = $result->getContent();
}
if ($result instanceof RestException)
{
throw $result;
}
if ($result === null)
{
$errorCollection->add($controller->getErrors());
if (!$errorCollection->isEmpty())
{
throw $this->createExceptionFromErrors($errorCollection->toArray());
}
}
return $this->processData($result);
}