public function afterRoute(&$className, &$method) { $user = User::getCurrent(); $reflection = new ReflectionMethod($className, $method); $docComment = $reflection->getDocComment(); // $this->isJson = $this->isJSON($docComment); if (strpos($docComment, '@Authorization') !== false && !$user) { $this->black = true; } $reflection = new ReflectionObject(new $className()); $docCommentC = $reflection->getDocComment(); if (strpos($docCommentC, '@Authorization') !== false && !$user) { $this->black = true; } if (strpos($docComment, '@Admin') !== false || strpos($docCommentC, '@Admin') !== false) { if ($user && !$user->isAdmin()) { $this->data['message'] = '你不是管理员,无法访问此页面'; $this->black = true; } } if ($this->black) { if ($this->isJson) { Template::setContext($this->data); Filter::preRender(); } else { Message::show($this->data['message'], 'auth/login', 3); } } }
/** * Show text and redirect to another page * @param string $text Content * @param string $link Target page * @param int $timeout Time before redirect */ public static function show($text, $link = null, $timeout = 3) { Template::setView('Misc/Redirect'); Template::putContext('text', $text); Template::putContext('timeout', $timeout); Template::putContext('link', $link === null ? null : Response::generateURL($link)); Filter::preRender(); Template::render(); Filter::afterRender(); exit; }
/** * Show text and redirect to another page * @param string $text Content * @param string $link Target page * @param int $timeout Time before redirect */ public static function show($text, $link = null, $timeout = 3) { Template::setView('Misc/Redirect'); if (is_array($text)) { array_unshift($text, $text[0]); // Set fallback string Template::putContext('text', call_user_func_array(array('I18N', 'parse'), $text)); } else { Template::putContext('text', I18N::parse($text, $text)); } Template::putContext('timeout', $timeout); Template::putContext('link', $link === null ? null : Response::generateURL($link)); Filter::preRender(); Template::render(); Filter::afterRender(); exit; }
private function findController($requestPath) { $route = array(); $parameter = array(); $context = null; $key = strtolower($requestPath); if ($this->StaticRoute[$key]) { $route = $this->StaticRoute[$key]; } else { foreach ($this->DynamicRoute as $router) { if (!preg_match($router['regexp'], $requestPath, $matches)) { continue; } // Remove the request string array_shift($matches); $route = $router['callback']; $parameter = $matches; break; } } if (!$route) { if ($this->FallbackRouter) { $route = $this->FallbackRouter; } else { throw new Error(I18N::parse('Error.Messages.PageNotExists', 'The request URL is not exists'), 404); } } list($className, $method) = $route; Filter::afterRoute($className, $method); $controller = new $className(); if ($parameter) { $context = call_user_func_array(array($controller, $method), $parameter); } else { $context = $controller->{$method}(); } if ($context) { Template::setContext($context); } Filter::preRender(); Template::render(); Filter::afterRender(); }