Source for file jsonresponse.php

Documentation is available at jsonresponse.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_languages
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * JSON Response class
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_languages
  17.  * @since       2.5
  18.  * @deprecated    4.0
  19.  */
  20. {
  21.     /**
  22.      * Determines whether the request was successful
  23.      *
  24.      * @var    boolean 
  25.      * @since  2.5
  26.      */
  27.     public $success = true;
  28.  
  29.     /**
  30.      * Determines whether the request wasn't successful.
  31.      * This is always the negation of $this->success,
  32.      * so you can use both flags equivalently.
  33.      *
  34.      * @var    boolean 
  35.      * @since  2.5
  36.      */
  37.     public $error = false;
  38.  
  39.     /**
  40.      * The main response message
  41.      *
  42.      * @var    string 
  43.      * @since  2.5
  44.      */
  45.     public $message = null;
  46.  
  47.     /**
  48.      * Array of messages gathered in the JApplication object
  49.      *
  50.      * @var    array 
  51.      * @since  2.5
  52.      */
  53.     public $messages = null;
  54.  
  55.     /**
  56.      * The response data
  57.      *
  58.      * @var    mixed 
  59.      * @since  2.5
  60.      */
  61.     public $data = null;
  62.  
  63.     /**
  64.      * Constructor
  65.      *
  66.      * @param   mixed    $response  The Response data
  67.      * @param   string   $message   The main response message
  68.      * @param   boolean  $error     True, if the success flag shall be set to false, defaults to false
  69.      *
  70.      * @since        2.5
  71.      * @deprecated    4.0     Use JResponseJson instead
  72.      */
  73.     public function __construct($response null$message null$error false)
  74.     {
  75.         JLog::add('Class JJsonResponse is deprecated. Use class JResponseJson instead.'JLog::WARNING'deprecated');
  76.  
  77.         $this->message = $message;
  78.  
  79.         // Get the message queue
  80.         $messages JFactory::getApplication()->getMessageQueue();
  81.  
  82.         // Build the sorted messages list
  83.         if (is_array($messages&& count($messages))
  84.         {
  85.             foreach ($messages as $message)
  86.             {
  87.                 if (isset($message['type']&& isset($message['message']))
  88.                 {
  89.                     $lists[$message['type']][$message['message'];
  90.                 }
  91.             }
  92.         }
  93.  
  94.         // If messages exist add them to the output
  95.         if (isset($lists&& is_array($lists))
  96.         {
  97.             $this->messages = $lists;
  98.         }
  99.  
  100.         // Check if we are dealing with an error
  101.         if ($response instanceof Exception)
  102.         {
  103.             // Prepare the error response
  104.             $this->success = false;
  105.             $this->error = true;
  106.             $this->message    = $response->getMessage();
  107.         }
  108.         else
  109.         {
  110.             // Prepare the response data
  111.             $this->success = !$error;
  112.             $this->error = $error;
  113.             $this->data = $response;
  114.         }
  115.     }
  116.  
  117.     /**
  118.      * Magic toString method for sending the response in JSON format
  119.      *
  120.      * @return  string  The response in JSON format
  121.      *
  122.      * @since   2.5
  123.      */
  124.     public function __toString()
  125.     {
  126.         return json_encode($this);
  127.     }
  128. }

Documentation generated on Tue, 19 Nov 2013 15:06:19 +0100 by phpDocumentor 1.4.3