- md5
- 59d47c89f366fb962b7a654c1a707f60
- sha1
- 1a16d556b4d91ad69d9a85827c5c40afe0f62ad2
- sha256
- 9adfa62d5a19303283f25cbac28cdb1612e878d617426f8af484d723cc7490d8
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
<?php
/**
* @package Joomla.Installation
* @subpackage Controller
*
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Installation\Controller;
defined('_JEXEC') or die;
use Joomla\CMS\Installation\Response\JsonResponse;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Session\Session;
use Joomla\CMS\Factory;
/**
* Default JSON controller class for the Joomla Installer controllers.
*
* @since 4.0.0
*/
abstract class JSONController extends BaseController
{
/**
* Method to send a JSON response. The data parameter
* can be an Exception object for when an error has occurred or
* a JsonResponse for a good response.
*
* @param mixed $response JsonResponse on success, Exception on failure.
*
* @return void
*
* @since 4.0.0
*/
protected function sendJsonResponse($response)
{
$this->app->mimeType = 'application/json';
// Very crude workaround to give an error message when JSON is disabled
if (!function_exists('json_encode') || !function_exists('json_decode'))
{
$this->app->setHeader('status', 500);
echo '{"token":"' . Session::getFormToken(true) . '","lang":"' . Factory::getLanguage()->getTag()
. '","error":true,"header":"' . \JText::_('INSTL_HEADER_ERROR') . '","message":"' . \JText::_('INSTL_WARNJSON') . '"}';
return;
}
// Check if we need to send an error code.
if ($response instanceof \Exception)
{
// Send the appropriate error code response.
$this->app->setHeader('status', $response->getCode(), true);
}
// Send the JSON response.
echo json_encode(new JsonResponse($response));
}
/**
* Checks for a form token, if it is invalid a JSOn response with the error code 403 is sent.
*
* @return void
*
* @since 4.0.0
* @see Session::checkToken()
*/
public function checkValidToken()
{
// Check for request forgeries.
Session::checkToken() or $this->sendJsonResponse(new \Exception(\JText::_('JINVALID_TOKEN'), 403));
}
}
No other release has this exact content. See every version of this file.