<?php session_start(); require_once dirname(__FILE__) . '/config/globals.php'; require_once dirname(__FILE__) . '/config/autoload.php'; use Libs\Route; use Libs\RouteCollection; use Libs\Router; $collection = new RouteCollection(); $collection->attachRoute(new Route('/', array('_controller' => 'Controllers\\HomeController::init', 'methods' => 'GET'))); $router = new Router($collection); $router->setBasePath('/'); $route = $router->matchCurrentRequest();
/** * Create routes by array, and return a Router object * * @param array $config 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; }