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
 /**
  * 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);
 }
Example #2
0
 public function testParseConfig()
 {
     $config = Config::loadFromFile(__DIR__ . '/../../Fixtures/router.yaml');
     $router = Router::parseConfig($config);
     self::assertAttributeEquals($config['base_path'], 'basePath', $router);
 }