示例#1
0
文件: Http.php 项目: pyrsmk/lumy
 protected function _getController()
 {
     // Sort routes
     uasort($this->_routes, function ($a, $b) {
         return strlen($a->getChain()) - strlen($b->getChain());
     });
     // Get request object
     $lumy = Lumy\Http::getInstance();
     $request = $lumy['request'];
     // Get request method
     $method = $request->getMethod();
     // Search
     $arguments = false;
     foreach ($this->_routes as $route) {
         // Just match the request chain when its method is valid
         if (strpos($route->getChain(), $method) !== 0) {
             continue;
         } else {
             $route_chain = substr($route->getChain(), strpos($route->getChain(), '#') + 1);
             // By Scheme/Host/RequestURI
             if (strpos($route_chain, 'http:') === 0 || strpos($route_chain, 'https:') === 0) {
                 $chain = $request->getChain();
             } elseif (strpos($route_chain, '//') === 0) {
                 $chain = '//' . $request->getHost() . $request->getRequestUri();
             } elseif (strpos($request->getResourceUri(), $route_chain) === false && $request->getRootUri() && strpos($route_chain, $request->getRootUri()) === 0) {
                 $chain = $request->getRequestUri();
             } else {
                 $chain = $request->getResourceUri();
             }
         }
         // Is this the good route?
         if (($arguments = $route->match($method . '#' . $chain)) !== false) {
             break;
         }
     }
     // No controller found
     if ($arguments === false) {
         return false;
     }
     // Controller found
     return function () use($route, $arguments) {
         return call_user_func_array($route->getController(), $arguments);
     };
 }
示例#2
0
文件: Http.php 项目: pyrsmk/lumy
 public function redirect($url, $status = 302)
 {
     $this->setStatus($status);
     if ($url[0] == '/') {
         $lumy = Lumy::getInstance();
         $url = $lumy['request']->getRootUri() . $url;
     }
     $this->setHeader('Location', $url);
     exit;
 }