/** * @return Controller * * @throws Exception */ public function dispatch() { $match = $this->match(); if (class_exists($this->_controller_classname)) { $controller = $this->_controller_classname; } else { Cordillera::$exception = new Exception(translate('%s not found', [$this->_controller_classname]), 500, Exception::ERROR); $controller = 'cordillera\\middlewares\\Controller'; } $this->handler = ''; if (isset($match['friendly']) && !$match['friendly']) { $this->handler = $match['handler'] ? $match['handler'] : $this->_default_route; } elseif (isset($match['friendly']) && $match['friendly']) { $this->handler = $match['handler']; $_GET = array_merge($_GET, $match['params']); } elseif (!isset($match['friendly'])) { $this->handler = $match != '/' && $match != '' ? $match : $this->_default_route; } return new $controller($this); }