Exemplo n.º 1
0
 /**
  * 执行handle 并返回response
  */
 public function handle(Request $request)
 {
     $this->prepareCli($request);
     $ipath = $this->getTruePath($request->getPathInfo());
     $route = Route::match($ipath);
     $request->route = new RouteBag($route);
     $this->init($request);
     try {
         $this->afterRoute($request);
         if ($route && is_object($route['callback']) && get_class($route['callback']) == 'Closure') {
             $response = $route['callback']($request);
         } elseif ($route) {
             $response = call_user_func($route['callback'], $request);
         } else {
             return new Response('', 404);
         }
         if ($response instanceof Response) {
             return $response;
         } elseif ($response === null) {
             return new Response('', 206);
         } else {
             return new Response($response);
         }
     } catch (ErrorException $e) {
         return new Response($e->getMessage(), 406);
     } catch (Exception $e) {
         throw $e;
     }
 }
Exemplo n.º 2
0
 protected function prepare($route)
 {
     $this->route = (array) $route + $this->route;
     $this->params = $this->route['segments'];
     $segments = Route::getSegments($this->route['baseroute']);
     foreach ($segments as $i => $segment) {
         if (substr($segment, 0, 1) == '{' && substr($segment, -1, 1) == '}') {
             $key = trim($segment, '{}');
             $this->setParameter($key, $this->getParameter($i));
         }
     }
 }
Exemplo n.º 3
0
 /**
  * 执行handle 并返回response
  */
 public function handle(Request $request)
 {
     $this->prepareCli($request);
     $route = Route::match($request->getPathInfo());
     $request->route = new RouteBag($route);
     $this->init($request);
     $this->afterRoute($request);
     if ($route && is_object($route['callback']) && get_class($route['callback']) == 'Closure') {
         $response = $route['callback']($request);
     } elseif ($route) {
         $response = call_user_func($route['callback'], $request);
     } else {
         return new Response('', 404);
     }
     if ($response instanceof Response) {
         return $response;
     } elseif ($response === null) {
         return new Response('', 204);
     } else {
         return new Response($response);
     }
 }
Exemplo n.º 4
0
function route_delete($route)
{
    return Route::delete($route);
}