PHPRouter\Router::parseConfig PHP Method

parseConfig() public static method

Create routes by array, and return a Router object
public static parseConfig ( array $config ) : Router
$config array provide by Config::loadFromFile()
return Router
    public static function parseConfig(array $config)
    {
        $collection = new RouteCollection();
        foreach ($config['routes'] as $name => $route) {
            $collection->attachRoute(new Route($route[0], array('_controller' => str_replace('.', '::', $route[1]), 'methods' => $route[2], 'name' => $name)));
        }
        $router = new Router($collection);
        if (isset($config['base_path'])) {
            $router->setBasePath($config['base_path']);
        }
        return $router;
    }

Usage Example

 /**
  * Router runner
  *
  * @throws NotFoundException
  * @return bool|\PHPRouter\Route
  */
 public function run()
 {
     $routes = Config::loadFromFile($this->routePath);
     $router = Route::parseConfig($routes);
     $exec = $router->matchCurrentRequest();
     if ($exec) {
         return $exec;
     }
     throw new NotFoundException('Route does not found', NotFoundException::CODE);
 }
All Usage Examples Of PHPRouter\Router::parseConfig