Webiny\Component\Router\Loader\ConfigLoader::getRouteCollection PHP Method

getRouteCollection() public method

Builds and returns RouteCollection instance.
public getRouteCollection ( ) : RouteCollection
return Webiny\Component\Router\Route\RouteCollection
    public function getRouteCollection()
    {
        foreach ($this->config as $name => $routeConfig) {
            $this->routeCollection->add($name, $this->processRoute($routeConfig));
        }
        unset($this->config);
        return $this->routeCollection;
    }

Usage Example

Example #1
0
 /**
  * Initializes the Route by reading the default config, registering routes and creating
  * necessary object instances.
  * Note: this method is called automatically when you do Router::setConfig().
  */
 public function initialize()
 {
     // check if we have already initialized the router
     if ($this->initializedFlag) {
         return;
     }
     // do initialization
     $this->loader = new ConfigLoader(self::getConfig()->get('Routes', new ConfigObject([])));
     self::$routeCollection = $this->loader->getRouteCollection();
     $this->urlMatcher = new UrlMatcher();
     $this->urlGenerator = new UrlGenerator();
     $this->setCache(self::getConfig()->get('Cache', false));
     $this->initializedFlag = true;
     //print_r(Router::getConfig()->toArray());
 }