Esempio n. 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;
 }
Esempio n. 2
0
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $moduleOptions = array();
     foreach ($this->moduleManager->modules() as $module) {
         $moduleOptions[get_class($module)] = $module->getName();
     }
     $resolver->setDefaults(array('choices' => $moduleOptions));
 }
Esempio n. 3
0
 protected function importRoutes($resource, $type = null)
 {
     //print '-'.$resource.'--'.$type;
     $routes = $this->moduleManager->loadRoutes($resource, $type);
     // print 'В итоге роуты ресурса '.$resource;
     //var_dump ($routes);
     //exit();
     if ($routes) {
         foreach ($routes->all() as $name => $route) {
             $this->routeCollection->add($name, $route);
         }
     }
 }
 /**
  * @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;
 }
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     //Modules by bundle and translated
     $resolver->setDefaults(array('choices' => $this->moduleManager->modules(true, true)));
 }
Esempio n. 6
0
 /**
  * Return route name. If route can be multiples - it prefixes with rubricFullPathCode
  * rubric: /some/path/, route : index , route name will be some_path_index
  * @param $name
  * @return string
  */
 protected function prepareRouteName($name)
 {
     return $this->allowMultiple && $this->rubric ? $this->moduleManager->getEntityRouter()->routeNameForRubricAction($this->rubric, $name) : $name;
 }