Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
controllerbuilder.php
1<?php
2namespace Bitrix\Main\Engine;
3
4
6
8{
9 public static function build(string $controllerClass, $options): Controller
10 {
11 try
12 {
13 $scope = $options['scope'] ?? Controller::SCOPE_AJAX;
14 $currentUser = $options['currentUser'] ?? CurrentUser::get();
15
16 $reflectionClass = new \ReflectionClass($controllerClass);
17 if ($reflectionClass->isAbstract())
18 {
19 throw new ObjectException("Controller class should be non abstract.");
20 }
21
22 if (!$reflectionClass->isSubclassOf(Controller::class))
23 {
24 throw new ObjectException("Controller class should be subclass of \Bitrix\Main\Engine\Controller.");
25 }
26
30 $controller = $reflectionClass->newInstance();
31 $controller->setScope($scope);
32 $controller->setCurrentUser($currentUser);
33
34 return $controller;
35 }
36 catch (\ReflectionException $exception)
37 {
38 throw new ObjectException("Unable to construct controller {{$controllerClass}}.", $exception);
39 }
40 }
41}