Example #1
0
 /**
  * Load routes of the specified module from the module's configuration file.
  *
  * @param AbstractBundle $bundle
  *
  * @return RouteCollection[]
  */
 private function find(AbstractBundle $bundle)
 {
     if (!\ServiceUtil::hasContainer()) {
         \ServiceUtil::setContainer($this->container);
     }
     try {
         $path = $this->zikulaKernel->locateResource($bundle->getRoutingConfig());
     } catch (\InvalidArgumentException $e) {
         // Routing file does not exist (e.g. because the bundle could not be located).
         return [new RouteCollection(), new RouteCollection(), new RouteCollection()];
     }
     $name = $bundle->getName();
     $topRouteCollection = new RouteCollection();
     $middleRouteCollection = new RouteCollection();
     $bottomRouteCollection = new RouteCollection();
     /**
      * These are all routes of the module, as loaded by Symfony.
      * @var RouteCollection $routeCollection
      */
     $routeCollection = $this->import($path);
     // Add all resources from the imported route collection to the middleRouteCollection.
     // The actual collection (top, middle, bottom) to add the resources too does not matter,
     // they just must be added to one of them, so that they don't get lost.
     foreach ($routeCollection->getResources() as $resource) {
         $middleRouteCollection->addResource($resource);
     }
     // It would be great to auto-reload routes here if the module version changes or a module is uninstalled.
     // This is not yet possible, see
     // - https://github.com/symfony/symfony/issues/7176
     // - https://github.com/symfony/symfony/pull/15738
     // - https://github.com/symfony/symfony/pull/15692
     // $routeCollection->addResource(new ZikulaResource())
     /** @var Route $route */
     foreach ($routeCollection as $oldRouteName => $route) {
         //          set break here with $oldRouteName == 'zikula_routesmodule_route_renew'
         $this->fixRequirements($route);
         $this->prependBundlePrefix($route, $bundle);
         list($type, $func) = $this->setZikulaDefaults($route, $bundle, $name);
         $routeName = $this->getRouteName($oldRouteName, $name, $type, $func);
         if ($route->hasOption('zkPosition')) {
             switch ($route->getOption('zkPosition')) {
                 case 'top':
                     $topRouteCollection->add($routeName, $route);
                     break;
                 case 'bottom':
                     $bottomRouteCollection->add($routeName, $route);
                     break;
                 default:
                     throw new \RuntimeException('Unknown route position. Got "' . $route->getOption('zkPosition') . '", expected "top" or "bottom"');
             }
         } else {
             $middleRouteCollection->add($routeName, $route);
         }
     }
     return [$middleRouteCollection, $topRouteCollection, $bottomRouteCollection];
 }
Example #2
0
 /**
  * Returns the route's path prepended with the bundle prefix.
  *
  * @param null $container Can be used to set the container for \ServiceUtil in case it is not already set.
  *
  * @return string
  */
 public function getPathWithBundlePrefix($container = null)
 {
     if (!isset($this->options['zkNoBundlePrefix']) || !$this->options['zkNoBundlePrefix']) {
         $bundle = $this->getBundle();
         if (!\ServiceUtil::hasContainer()) {
             \ServiceUtil::setContainer($container);
         }
         $modinfo = \ModUtil::getInfoFromName($bundle);
         return "/" . $modinfo["url"] . $this->path;
     }
     return $this->path;
 }