Example #1
0
 public static function run($resource, $method)
 {
     $top = count(self::$stack) - 1;
     if ($top < 0) {
         return;
     }
     $isExternal = $top == 0;
     $resource = Route::route($resource, self::$stack[$top]);
     if (!self::isAvailable($resource, $method)) {
         if ($isExternal) {
             $resource = 'errors/access-denied';
         } else {
             return '';
         }
     }
     list($controller, $action, $data) = Url::route($resource, $method);
     self::$stack[$top] = array_merge(self::$stack[$top], $data);
     $handler = Url::handler($controller, $action);
     if ($isExternal) {
         Middleware::processBefore($resource, $action, self::$stack[$top], $method);
         self::runHandler($handler);
         Middleware::processAfter($resource, $action, self::$stack[$top], $method);
     } else {
         if (!self::runInternalHandler($handler)) {
             return '';
         }
     }
     if (!empty(self::$stack[$top]['display'])) {
         $handler .= '.' . self::$stack[$top]['display'];
     }
     if ($isExternal && self::$response->code == '404 Not Found') {
         list($controller, $action, $data) = Url::route('errors/not-found', 'get');
         $handler = Url::handler($controller, $action);
         self::$response->result("error", self::$response->code);
     }
     if ($isExternal && self::$response->code == '403 Forbidden') {
         list($controller, $action, $data) = Url::route('errors/not-found', 'get');
         $handler = Url::handler($controller, $action);
         self::$response->result("error", self::$response->code);
     }
     $r = self::$response->fetch($handler, $isExternal);
     if ($isExternal) {
         Language::rewrite($r);
     }
     return $r;
 }