Esempio n. 1
0
 public function run()
 {
     $uri = $this->getURI();
     foreach ($this->routes as $uriPattern => $path) {
         if (preg_match("~{$uriPattern}~", $uri)) {
             $internalRoute = preg_replace("~{$uriPattern}~", $path, $uri);
             $segments = explode('/', $internalRoute);
             $controllerName = ucfirst(array_shift($segments)) . 'Controller';
             $nameAction = lcfirst(array_shift($segments)) . 'Action';
             $result = null;
             $class = "\\app\\controllers\\" . $controllerName;
             $controllerObject = new $class();
             if (method_exists($controllerObject, $nameAction)) {
                 $result = $controllerObject->{$nameAction}();
                 if (!empty($_POST) || !empty($_GET)) {
                     ApiResponse::afterExecuteRoute($result);
                 }
             }
             if ($result != null) {
                 break;
             } else {
                 require_once ROOT . '/app/views/error/index.phtml';
             }
         }
     }
 }