• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/engine/controllerbuilder.php
  • Класс: BitrixMainEngineControllerBuilder
  • Вызов: ControllerBuilder::build
static function build(string $controllerClass, $options): Controller
{
	try
	{
		$scope = $options['scope'] ?? Controller::SCOPE_AJAX;
		$currentUser = $options['currentUser'] ?? CurrentUser::get();

		$reflectionClass = new ReflectionClass($controllerClass);
		if ($reflectionClass->isAbstract())
		{
			throw new ObjectException("Controller class should be non abstract.");
		}

		if (!$reflectionClass->isSubclassOf(Controller::class))
		{
			throw new ObjectException("Controller class should be subclass of BitrixMainEngineController.");
		}

		/** @var Controller $controller */
		/** @see BitrixMainEngineController::__construct */
		/** @see BitrixMainEngineController::forward */
		$controller = $reflectionClass->newInstance();
		$controller->setScope($scope);
		$controller->setCurrentUser($currentUser);

		return $controller;
	}
	catch (ReflectionException $exception)
	{
		throw new ObjectException("Unable to construct controller {{$controllerClass}}.", $exception);
	}
}