Example #1
0
 /**
  * @param string $resource
  * @param null $type
  * @return \Symfony\Component\Routing\RouteCollection
  */
 public function load($resource, $type = null)
 {
     $routes = new RouteCollection();
     $logger = $this->container->get('logger');
     $logger->info('Загрузка рубрик для построения роутинга');
     $a = microtime(true);
     $rubrics = $this->em->getRepository('ApplicationIphpCoreBundle:Rubric')->createQueryBuilder('r')->orderBy('r.level', 'DESC')->getQuery()->getResult();
     foreach ($rubrics as $rubric) {
         $controller = $rubric->getControllerName();
         $rubricRoutes = null;
         //В контроллере можеть быть: Класс модуля
         if ($controller && substr($controller, -6) == 'Module') {
             $module = $this->moduleManager->getModuleFromRubric($rubric);
             if ($module) {
                 $rubricRoutes = $module->getRoutes();
             }
         }
         if ($rubricRoutes) {
             foreach ($rubricRoutes as $route) {
                 $route->setDefault('_rubric', $rubric->getFullPath());
             }
             $routes->addCollection($rubricRoutes, substr($rubric->getFullPath(), 0, -1));
         }
     }
     $b = microtime(true) - $a;
     $logger->info('Загрузили роуты за' . $b . ' с');
     return $routes;
 }
 /**
  * @param string $resource
  * @param null $type
  * @return \Symfony\Component\Routing\RouteCollection
  */
 public function load($resource, $type = null)
 {
     $routes = new RouteCollection();
     $this->logger->info('Create route collection from database');
     $a = microtime(true);
     $rubrics = $this->em->getRepository('ApplicationIphpCoreBundle:Rubric')->createQueryBuilder('r')->orderBy('r.level', 'DESC')->getQuery()->getResult();
     foreach ($rubrics as $rubric) {
         $controller = $rubric->getControllerName();
         $rubricRoutes = null;
         //В контроллере можеть быть: Класс модуля
         if ($controller && substr($controller, -6) == 'Module') {
             $moduleError = '';
             try {
                 $module = $this->moduleManager->getModuleFromRubric($rubric);
                 if ($module) {
                     $rubricRoutes = $module->getRoutes();
                     if (count($resources = $module->getRouteResources())) {
                         $rubricRoutes->addCollection($this->importResources($resources));
                     }
                 }
             } catch (Exception $e) {
                 $moduleError = $e->getMessage();
             }
             $change = false;
             if ($moduleError) {
                 $change = true;
                 $rubric->setModuleError($moduleError);
             } else {
                 if ($rubric->getModuleError()) {
                     $rubric->setModuleError(null);
                     $change = true;
                 }
             }
             if ($change) {
                 $this->em->persist($rubric);
                 $this->em->flush();
             }
         }
         if ($rubricRoutes) {
             if ($rubric->getLevel()) {
                 $rubricRoutes->addPrefix(substr($rubric->getFullPath(), 0, -1));
             }
             $rubricRoutes->addDefaults(array('_rubric' => $rubric->getFullPath()));
             $routes->addCollection($rubricRoutes);
         }
     }
     //$this->em->flush();
     $b = microtime(true) - $a;
     $this->logger->info('Routes load time' . $b . ' с');
     return $routes;
 }