Example #1
0
 /**
  * The serve method is where inversion of control occurs which delegates
  * control to another method in the controller.
  * 
  * The method name and arguments should have been extracted in the 
  * preprocessing step. Here we ensure that the method exists and that all 
  * required parameters are provided as arguments from the request string.
  * 
  * Call the method and return its response.
  *
  * @param DefaultRequest $request The HTTP request being served.
  * 
  * !Wrappable serve
  */
 function wrappedServe(Request $request)
 {
     $this->request = $request;
     $shortWiredResponse = $this->init();
     if ($shortWiredResponse instanceof Response) {
         $shortWiredResponse->meta->viewClass = 'LayoutsView';
         $shortWiredResponse->meta->viewsPrefix = '';
         return $shortWiredResponse;
     }
     $methodName = $request->meta->controllerMethod;
     $methodArguments = $request->meta->controllerMethodArguments;
     $useAssociativeArguments = $request->meta->useAssociativeArguments;
     // Does method exist? Do arguments match?
     if (method_exists($this, $methodName)) {
         $method = new ReflectionMethod($this, $methodName);
         $parameters = $method->getParameters();
         $callArguments = array();
         try {
             if ($useAssociativeArguments) {
                 $callArguments = $this->getCallArgumentsAssociative($parameters, $methodArguments);
             } else {
                 $callArguments = $this->getCallArgumentsSequential($parameters, $methodArguments);
             }
         } catch (RecessException $e) {
             throw new RecessException('Error calling method "' . $methodName . '" in "' . get_class($this) . '". ' . $e->getMessage(), array());
         }
         $response = $method->invokeArgs($this, $callArguments);
     } else {
         throw new RecessException('Error calling method "' . $methodName . '" in "' . get_class($this) . '". Method does not exist.', array());
     }
     if (!$response instanceof Response) {
         Library::import('recess.http.responses.OkResponse');
         $response = new OkResponse($this->request);
     }
     $descriptor = self::getClassDescriptor($this);
     if (!$response instanceof ForwardingResponse && !isset($response->meta->viewName)) {
         $response->meta->viewName = $methodName;
     }
     // TODO: Remove this deprecated viewClass at 0.3
     $response->meta->viewClass = $descriptor->viewClass;
     $response->meta->viewsPrefix = $descriptor->viewsPrefix;
     $response->meta->respondWith = $descriptor->respondWith;
     if (empty($response->data)) {
         $response->data = get_object_vars($this);
     }
     if (is_array($this->headers)) {
         foreach ($this->headers as $header) {
             $response->addHeader($header);
         }
     }
     if (is_array($response->data)) {
         $response->data['controller'] = $this;
         unset($response->data['request']);
         unset($response->data['headers']);
     }
     return $response;
 }
Example #2
0
 /**
  * Constructor
  * 
  * @param string $error       Error message
  * @param int    $status_code HTTP status code
  * @param string $forward_url Forward url
  * @access private
  * @see elgg_error_response
  */
 public function __construct($error = '', $status_code = ELGG_HTTP_OK, $forward_url = REFERRER)
 {
     parent::__construct($error, $status_code, $forward_url);
 }
Example #3
0
 /**
  * Constructor
  *
  * @param string $forward_url Forward url
  * @param int    $status_code HTTP status code
  * @access private
  * @see elgg_redirect_response
  */
 public function __construct($forward_url = REFERRER, $status_code = ELGG_HTTP_FOUND)
 {
     parent::__construct('', $status_code, $forward_url);
 }