예제 #1
0
파일: Api.php 프로젝트: crlang44/frapi
 /**
  * Process Output
  *
  * This method will process the output by getting
  *
  * @return string  The output
  */
 public function processOutput()
 {
     // We check if we have errors, if we don't then we can process normally
     /**
      * Handle the headers and depending on whether they are a PUT, POST, DELETE, GET
      * we should invoke:
      *   $this->actionContext->executePost();
      *   $this->actionContext->executePut();
      *   $this->actionContext->executeDelete();
      *   $this->actionContext->executeGet();
      *   $this->actionContext->executeHead();
      */
     $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : false;
     $action = 'executeAction';
     if ($method !== false) {
         $action = 'execute' . ucfirst(strtolower($method));
     }
     $response = $this->actionContext->setAction($action)->{$action}();
     // Make sure we use a Frapi_Response.
     if (!$response instanceof Frapi_Response) {
         $response = new Frapi_Response(array('data' => $response));
     }
     /**
      * Here we look for the temporary params so we can
      * automatically replace the jsonp_callback and handle
      * it in the OutputHandlers transparently.
      */
     $tmpParams = $this->actionContext->getParams();
     if (isset($tmpParams['jsonp_callback'])) {
         $response->setData($response->getData() + array('jsonp_callback' => $tmpParams['jsonp_callback']));
     }
     unset($tmpParams);
     /**
      * If the action result is NOT an instance of
      * Error, we can assume that it's valid
      * output so keep going and output the result
      */
     return $this->getOutputInstance($this->getFormat())->setOutputAction($this->getAction())->populateOutput($response->getData(), $this->actionContext->getTemplateFileName())->sendHeaders($response)->executeOutput();
 }