[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/installation/src/Response/ -> JsonResponse.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Installation
   5   * @subpackage  Response
   6   *
   7   * @copyright   (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9   */
  10  
  11  namespace Joomla\CMS\Installation\Response;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Language\Text;
  15  use Joomla\CMS\Session\Session;
  16  
  17  // phpcs:disable PSR1.Files.SideEffects
  18  \defined('_JEXEC') or die;
  19  // phpcs:enable PSR1.Files.SideEffects
  20  
  21  /**
  22   * JSON Response class for the Joomla Installer.
  23   *
  24   * @since  3.1
  25   */
  26  class JsonResponse
  27  {
  28      /**
  29       * Constructor for the JSON response
  30       *
  31       * @param   mixed  $data  Exception if there is an error, otherwise, the session data
  32       *
  33       * @since   3.1
  34       */
  35      public function __construct($data)
  36      {
  37          // The old token is invalid so send a new one.
  38          $this->token = Session::getFormToken(true);
  39  
  40          // Get the language and send its tag along
  41          $this->lang = Factory::getLanguage()->getTag();
  42  
  43          // Get the message queue
  44          $messages = Factory::getApplication()->getMessageQueue();
  45  
  46          // Build the sorted message list
  47          if (is_array($messages) && count($messages)) {
  48              foreach ($messages as $msg) {
  49                  if (isset($msg['type'], $msg['message'])) {
  50                      $lists[$msg['type']][] = $msg['message'];
  51                  }
  52              }
  53          }
  54  
  55          // If messages exist add them to the output
  56          if (isset($lists) && is_array($lists)) {
  57              $this->messages = $lists;
  58          }
  59  
  60          // Check if we are dealing with an error.
  61          if ($data instanceof \Throwable) {
  62              // Prepare the error response.
  63              $this->error   = true;
  64              $this->header  = Text::_('INSTL_HEADER_ERROR');
  65              $this->message = $data->getMessage();
  66          } else {
  67              // Prepare the response data.
  68              $this->error = false;
  69              $this->data  = $data;
  70          }
  71      }
  72  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer