Пример #1
0
 public function __construct($routes)
 {
     $router_factory = new RouterFactory();
     $this->_router = $router_factory->newInstance();
     // home route
     $this->_router->addGet('home', '/');
     // routes from config
     foreach ($routes as $name => $values) {
         foreach ($values['actions'] as $action) {
             $method = 'add' . Utils::firstToUpper($action['verb']);
             $this->_router->{$method}($name . '.' . $action['name'], '/' . $values['prefix'] . $action['pattern'])->addTokens(array('id' => '\\d+'));
         }
     }
 }
Пример #2
0
 public function dispatch($route)
 {
     if (empty($route)) {
         $this->_errorController->error('404 unknown controller');
     } else {
         $className = Utils::firstToUpper($route['controller']) . 'Controller';
         $controller = new $className();
         $action = 'action' . Utils::firstToUpper($route['action']);
         try {
             $controller->{$action}($route['id']);
         } catch (Exception $e) {
             $errorController = new \ErrorController();
             $this->_errorController->error($e->getMessage());
         }
     }
 }