Source for file jResponseJsonrpc.class.php

Documentation is available at jResponseJsonrpc.class.php

  1. <?php
  2. /**
  3. * @package     jelix
  4. * @subpackage  core_response
  5. * @author      Laurent Jouanneau
  6. * @contributor Loic Mathaud
  7. * @copyright   2005-2010 Laurent Jouanneau
  8. * @copyright   2007 Loic Mathaud
  9. * @link        http://www.jelix.org
  10. * @licence     GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
  11. */
  12.  
  13. /**
  14. * Response for jsonrpc protocol
  15. * @package  jelix
  16. * @subpackage core_response
  17. * @see jResponse
  18. * @see http://json-rpc.org/wiki/specification
  19. */
  20.  
  21. final class jResponseJsonRpc extends jResponse {
  22.     /**
  23.     * @var string 
  24.     */
  25.     protected $_type = 'jsonrpc';
  26.  
  27.     /**
  28.      * PHP data you want to return
  29.      * @var mixed 
  30.      */
  31.     public $response = null;
  32.  
  33.  
  34.     public function output(){
  35.         global $gJCoord;
  36.  
  37.         $this->_httpHeaders['Content-Type'] = "application/json";
  38.         if($gJCoord->request->jsonRequestId !== null){
  39.             $content = jJsonRpc::encodeResponse($this->response, $gJCoord->request->jsonRequestId);
  40.             $this->_httpHeaders['Content-length'] = strlen($content);
  41.             $this->sendHttpHeaders();
  42.             echo $content;
  43.         }
  44.         else {
  45.             $this->_httpHeaders['Content-length'] = '0';
  46.             $this->sendHttpHeaders();
  47.         }
  48.         return true;
  49.     }
  50.  
  51.     public function outputErrors(){
  52.         global $gJCoord;
  53.         $e = $gJCoord->getErrorMessage();
  54.         if ($e) {
  55.             $errorCode = $e->getCode();
  56.             if ($errorCode > 5000)
  57.                 $errorMessage = $e->getMessage();
  58.             else
  59.                 $errorMessage = $gJCoord->getGenericErrorMessage();
  60.         }
  61.         else {
  62.             $errorCode = -1;
  63.             $errorMessage = $gJCoord->getGenericErrorMessage();
  64.         }
  65.         $this->clearHttpHeaders();
  66.         $this->_httpStatusCode ='500';
  67.         $this->_httpStatusMsg ='Internal Server Error';
  68.         $this->_httpHeaders['Content-Type'] = "application/json";
  69.         $content = jJsonRpc::encodeFaultResponse($errorCode, $errorMessage, $gJCoord->request->jsonRequestId);
  70.         $this->_httpHeaders['Content-length'] = strlen($content);
  71.         $this->sendHttpHeaders();
  72.         echo $content;
  73.     }
  74. }

Documentation generated on Mon, 19 Sep 2011 14:13:24 +0200 by phpDocumentor 1.4.3