/** * Define and load page components into the ComponentManager. * @todo Полный рефакторинг! */ public function loadComponents(callable $getStructure) { // определяем и загружаем описания content- и layout- частей страницы $structure = call_user_func($getStructure, $this->getID()); // вызывается ли компонент в single режиме? $actionParams = $this->request->getPath(Request::PATH_ACTION); if (sizeof($actionParams) > 1 && $actionParams[0] == self::SINGLE_SEGMENT) { /* * Устанавливаем смещение пути на количество существующих * сегментов + 1 зарезирвированный сегмент + 1 сегмент * имени компонента. */ $this->request->setPathOffset($this->request->getPathOffset() + 2); $this->setProperty('single', 'single'); if ($actionParams[1] == 'pageToolBar') { $this->componentManager->add($this->componentManager->createComponent('pageToolBar', 'Energine\\share\\components\\DivisionEditor', ['state' => 'showPageToolbar'])); } else { if (!($blockDescription = ComponentManager::findBlockByName($structure, $actionParams[1]))) { throw new SystemException('ERR_NO_SINGLE_COMPONENT', SystemException::ERR_CRITICAL, $actionParams[1]); } if (E()->getController()->getViewMode() == DocumentController::TRANSFORM_STRUCTURE_XML) { $int = new IRQ(); $int->setStructure($blockDescription); throw $int; } if ($c = ComponentManager::createBlockFromDescription($blockDescription)) { $this->componentManager->add($c); } } } else { if (E()->getController()->getViewMode() == DocumentController::TRANSFORM_STRUCTURE_XML) { $int = new IRQ(); $int->setStructure($structure); throw $int; } foreach ($structure->children() as $XML) { if ($c = ComponentManager::createBlockFromDescription($XML)) { $this->componentManager->add($c); } } /* * Добавляем к набору компонентов страницы * обязательные стандартные компоненты: * - BreadCrumbs */ $this->componentManager->add($this->componentManager->createComponent('breadCrumbs', $this->breadCrumbsClass)); //Если пользователь не авторизован и авторизационный домен не включает текущеий домен - то добавляем компонент для кроссдоменной авторизации if (!$this->user->isAuthenticated() && strpos(E()->getSiteManager()->getCurrentSite()->host, $this->getConfigValue('site.domain')) === false) { $this->componentManager->add($this->componentManager->createComponent('cdAuth', 'Energine\\share\\components\\CrossDomainAuth')); } } }
/** * Create component container from description. * * @param \SimpleXMLElement $containerDescription Container description. * @param array $externalParams Additional attributes. * @return ComponentContainer * * @throws SystemException ERR_NO_CONTAINER_NAME */ public static function createFromDescription(\SimpleXMLElement $containerDescription, array $externalParams = []) { $properties['tag'] = $containerDescription->getName(); $attributes = $containerDescription->attributes(); if (in_array($containerDescription->getName(), ['page', 'content'])) { $properties['name'] = $properties['tag']; } elseif (!isset($attributes['name'])) { $properties['name'] = uniqid('name_'); } foreach ($attributes as $propertyName => $propertyValue) { $properties[(string) $propertyName] = (string) $propertyValue; } $name = $properties['name']; unset($properties['name']); $properties = array_merge($properties, $externalParams); $value = null; $containerDescriptionValue = trim((string) $containerDescription); if (!empty($containerDescriptionValue)) { $value = $containerDescriptionValue; } $result = new ComponentContainer($name, $properties, $value); foreach ($containerDescription as $blockDescription) { if ($c = ComponentManager::createBlockFromDescription($blockDescription, $externalParams)) { $result->add($c); } } return $result; }