Example #1
0
 /**
  * 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'));
         }
     }
 }