예제 #1
0
 /**
  * Call a given route and return the route's response.
  *
  * @return Response
  */
 public function call()
 {
     // Since "before" filters can halt the request cycle, we will return
     // any response from the before filters. Allowing filters to halt the
     // request cycle makes tasks like authorization convenient.
     //
     // The route is responsible for running the global filters, and any
     // filters defined on the route itself. Since all incoming requests
     // come through a route (either defined or ad-hoc), it makes sense
     // to let the route handle the global filters. If the route uses
     // a controller, the controller will only call its own filters.
     $before = array_merge(array('before'), $this->filters('before'));
     $response = Filter::run($before, array(), true);
     if (is_null($response) and !is_null($response = $this->response())) {
         if ($response instanceof Delegate) {
             $response = Controller::call($response->destination, $this->parameters);
         }
     }
     if (!$response instanceof Response) {
         $response = new Response($response);
     }
     // Stringify the response. We need to force the response to be
     // stringed before closing the session, since the developer may
     // be using the session within their views, so we cannot age
     // the session data until the view is rendered.
     $response->content = $response->render();
     $filters = array_merge($this->filters('after'), array('after'));
     Filter::run($filters, array($response));
     return $response;
 }
예제 #2
0
 /**
  * Execute a controller method with the given parameters.
  *
  * @param  string    $method
  * @param  array     $parameters
  * @return Response
  */
 public function execute($method, $parameters = array())
 {
     // Again, as was the case with route closures, if the controller
     // "before" filters return a response, it will be considered the
     // response to the request and the controller method will not be
     // used to handle the request to the application.
     $response = Filter::run($this->filters('before', $method), array(), true);
     if (is_null($response)) {
         // The developer may mark the controller as being "RESTful" which
         // indicates that the controller actions are prefixed with the
         // HTTP verb they respond to rather than the word "action".
         if ($this->restful) {
             $action = strtolower(Request::method()) . '_' . $method;
         } else {
             $action = "action_{$method}";
         }
         $response = call_user_func_array(array($this, $action), $parameters);
         // If the controller has specified a layout view. The response
         // returned by the controller method will be bound to that view
         // and the layout will be considered the response.
         if (is_null($response) and !is_null($this->layout)) {
             $response = $this->layout;
         }
     }
     if (!$response instanceof Response) {
         $response = new Response($response);
     }
     // Stringify the response. We need to force the response to be
     // stringed before closing the session, since the developer may
     // be using the session within their views, so we cannot age
     // the session data until the view is rendered.
     $response->content = $response->render();
     Filter::run($this->filters('after', $method), array($response));
     return $response;
 }