48 $this->request = $request;
50 $this->component = $this->request->getQuery(
'c') ?:
null;
51 $this->mode = $this->request->getQuery(
'mode') ?:
null;
52 $this->action = $this->request->getQuery(
'action');
54 if (!\is_string($this->component))
56 $this->component =
null;
58 if (!\is_string($this->mode))
60 $this->component =
null;
62 if (!\is_string($this->action))
67 if ($this->action && !$this->component)
69 list($this->vendor, $this->action) = $this->resolveVendor($this->action);
70 list(
$module, $this->action) = $this->resolveModuleAndAction($this->action);
76 private function resolveModuleAndAction(
$action)
78 $actionParts = explode(
'.',
$action);
79 $module = array_shift($actionParts);
80 $action = implode(
'.', $actionParts);
87 private function resolveVendor(
$action)
125 $class = \CBitrixComponent::includeComponentClass(
$componentName);
126 if (!is_subclass_of($class,
'CBitrixComponent'))
131 $parameters =
array();
132 if ($signedParameters)
134 $parameters = ParameterSigner::unsignParameters(
$componentName, $signedParameters);
142 throw new SystemException(
143 "The component {$this->component} must be implement interface \Bitrix\Main\Engine\Contract\Controllerable",
144 self::EXCEPTION_INVALID_COMPONENT_INTERFACE
161 if ($this->component)
163 return $this->getComponentControllerAndAction();
166 $this->includeModule($this->module);
168 if ($controllerAndAction)
170 return $controllerAndAction;
176 return array(
new $ajaxClass, $this->action);
179 private function getComponentControllerAndAction()
181 $componentAsString = var_export($this->component,
true);
182 if ($this->mode === self::COMPONENT_MODE_CLASS)
184 $component = $this->buildComponent($this->component, $this->request->getPost(
'signedParameters'));
188 "Could not build component instance {$componentAsString}",
189 self::EXCEPTION_INVALID_COMPONENT
195 elseif ($this->mode === self::COMPONENT_MODE_AJAX)
197 $ajaxClass = $this->includeComponentAjaxClass($this->component);
199 $controller = ControllerBuilder::build($ajaxClass, [
200 'scope' => Controller::SCOPE_AJAX,
208 $modeAsString = var_export($this->mode,
true);
209 throw new SystemException(
210 "Unknown ajax mode ({$modeAsString}) to work {$componentAsString}",
211 self::EXCEPTION_INVALID_AJAX_MODE
216 private function includeModule(
$module)
220 throw new SystemException(
221 "Invalid module name {$module}",
222 self::EXCEPTION_INVALID_MODULE_NAME
226 if (!Configuration::getInstance(
$module)->
get(
'controllers'))
228 throw new SystemException(
229 "Could not find configuration 'controllers' for module {$module}. Probably module is not installed or not configured properly.",
230 self::EXCEPTION_NO_CONFIGURATION
236 throw new SystemException(
"Could not find module {$module}", self::EXCEPTION_NO_MODULE);
240 private function includeComponentAjaxClass(
$name)
242 $path2Comp = \CComponentEngine::makeComponentPath(
$name);
243 if ($path2Comp ===
'')
245 throw new SystemException(
"{$name} is not a valid component name", self::EXCEPTION_INVALID_COMPONENT_NAME);
251 throw new SystemException(
"Could not find component by name {$name}", self::EXCEPTION_NO_COMPONENT);
257 throw new SystemException(
"Could not find ajax class {$componentPath}", self::EXCEPTION_NO_COMPONENT_AJAX_CLASS);
271 $beforeClasses = get_declared_classes();
272 $beforeClassesCount =
count($beforeClasses);
274 $afterClasses = get_declared_classes();
275 $afterClassesCount =
count($afterClasses);
276 $furthestClass =
null;
277 for (
$i = $afterClassesCount - 1;
$i >= $beforeClassesCount;
$i--)
280 is_subclass_of($afterClasses[
$i], Controller::class) ||
281 ($furthestClass && is_subclass_of($afterClasses[
$i], $furthestClass))
284 $furthestClass = $afterClasses[
$i];
288 return $furthestClass;
297 $this->request = $request;
static getControllerAndAction($vendor, $module, $action, $scope=Controller::SCOPE_AJAX)
const COMPONENT_MODE_AJAX
setRequest(HttpRequest $request)
const EXCEPTION_NO_MODULE
const COMPONENT_MODE_CLASS
const EXCEPTION_INVALID_COMPONENT_INTERFACE
const EXCEPTION_NO_CONFIGURATION
const EXCEPTION_NO_COMPONENT_AJAX_CLASS
const EXCEPTION_NO_COMPONENT
const EXCEPTION_INVALID_MODULE_NAME
const EXCEPTION_INVALID_COMPONENT
__construct(HttpRequest $request)
refineModuleName($vendor, $module)
const EXCEPTION_INVALID_COMPONENT_NAME
const EXCEPTION_INVALID_AJAX_MODE
static includeModule($moduleName)
static isValidModule(string $moduleName)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)