- md5
- c195509d1640ec191ff5d868dc36fec9
- sha1
- 61012bdf8334b878113e81b4b645e396e1902cac
- sha256
- 9e353e94f878d5868d024979e0e4333ff5b1e2f645ef70045ad4b234ed52d460
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
<?php
/**
* @package Joomla.Installation
* @subpackage Controller
*
* @copyright Copyright (C) 2005 - 2017 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 __DEPLOY_VERSION__
*/
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 __DEPLOY_VERSION__
*/
protected function sendJsonResponse($response)
{
// 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);
$this->app->setHeader('Content-Type', 'application/json; charset=utf-8');
$this->app->sendHeaders();
echo '{"token":"' . Session::getFormToken(true) . '","lang":"' . Factory::getLanguage()->getTag()
. '","error":true,"header":"' . \JText::_('INSTL_HEADER_ERROR') . '","message":"' . \JText::_('INSTL_WARNJSON') . '"}';
$this->app->close();
}
// 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());
$this->app->setHeader('Content-Type', 'application/json; charset=utf-8');
$this->app->sendHeaders();
}
// Send the JSON response.
echo json_encode(new JsonResponse($response));
// Close the application.
$this->app->close();
}
/**
* Checks for a form token, if it is invalid a JSOn response with the error code 403 is sent.
*
* @return void
*
* @since __DEPLOY_VERSION__
* @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.