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

processRoute() public method

Builds a Route instance based on the given route config.
public processRoute ( ConfigObject $routeConfig ) : Route
$routeConfig Webiny\Component\Config\ConfigObject A config object containing route parameters.
return Webiny\Component\Router\Route\Route
    public function processRoute(ConfigObject $routeConfig)
    {
        // base route
        $callback = $this->isString($routeConfig->Callback) ? $routeConfig->Callback : $routeConfig->Callback->toArray();
        $route = new Route($routeConfig->Path, $callback);
        // route options
        if (($options = $routeConfig->get('Options', false)) !== false) {
            $route->setOptions($options->toArray());
        }
        // host
        if (($host = $routeConfig->get('Host', false)) !== false) {
            $route->setHost($host);
        }
        // schemes
        if (($schemes = $routeConfig->get('Schemes', false)) !== false) {
            $route->setSchemes($schemes);
        }
        // methods
        if (($methods = $routeConfig->get('Methods', false)) !== false) {
            $route->setMethods($methods->toArray());
        }
        // tags
        if (($tags = $routeConfig->get('Tags', false)) !== false) {
            $route->setTags($tags->toArray());
        }
        return $route;
    }

Usage Example

Example #1
0
 /**
  * Adds a route to the beginning of the current route collection.
  *
  * @param ConfigObject $routes An instance of ConfigObject holding the routes.
  *
  * @return $this
  */
 public function prependRoutes(ConfigObject $routes)
 {
     foreach ($routes as $name => $routeConfig) {
         self::$routeCollection->prepend($name, $this->loader->processRoute($routeConfig));
     }
     return $this;
 }