/** * 每个请求层,最终被调用的方法 * * @return mixed */ public function handle() { Base::getLog()->debug(__METHOD__ . ' handle main flow - start'); if (!Route::exists('default')) { Base::getLog()->debug(__METHOD__ . ' set default route'); Route::set('default', '(<controller>(/<action>(/<id>)))')->defaults(['controller' => 'Site', 'action' => 'index']); } $this->flow->contexts['uri'] = Url::detectUri(); Base::getLog()->debug(__METHOD__ . ' handle main flow - end'); }
/** * 跳转到指定URI * * @param string $uri * @return $this */ public function location($uri = null) { if (null === $uri) { return $this->headers('Location'); } if (false === strpos($uri, '://')) { $uri = Url::site($uri, true, !empty(Base::$indexFile)); } $lastTime = gmdate("D, d M Y H:i:s", time()) . ' GMT+0800'; $this->headers('Cache-Control', 'no-cache'); $this->headers('Last Modified', $lastTime); $this->headers('Last Fetched', $lastTime); $this->headers('Expires', 'Thu Jan 01 1970 08:00:00 GMT+0800'); $this->headers('Location', $uri); return $this; }
/** * 根据指定的路由返回URL,等同于下面的代码: * * echo URL::site(Route::get($name)->uri($params), $protocol); * * @param string $name 路由名 * @param array $params URI参数 * @param mixed $protocol 协议字符串、布尔值、等等 * @return string */ public static function url($name, array $params = null, $protocol = null) { $route = Route::get($name); return $route->isExternal() ? $route->uri($params) : Url::site($route->uri($params), $protocol); }
/** * {@inheritdoc} */ public function redirect($uri = '', $code = 302) { Base::getLog()->debug(__METHOD__ . ' redirect page', ['url' => $uri, 'code' => $code]); if (false === strpos($uri, '://')) { $uri = Url::site($uri, true, !empty(Base::$indexFile)); } $lastTime = gmdate("D, d M Y H:i:s", time()) . ' GMT+0800'; $this->header('Cache-Control: no-cache'); $this->header('Last Modified: ' . $lastTime); $this->header('Last Fetched: ' . $lastTime); $this->header('Expires: Thu Jan 01 1970 08:00:00 GMT+0800'); $this->header('Location: ' . $uri); $this->code($code); $this->end(); }
/** * 创建一个当前请求的URL * * @param mixed $protocol 协议字符串 * @return string */ public function url($protocol = null) { return Url::site($this->uri, $protocol); }