CoreFiles by mySites.guru
JsonRenderer.php64 lines, 1,244 bytes, from Joomla_4.0.0-alpha8-Alpha-Full_Package.zip
Raw History Compare with 4.0.0-alpha7
md5
47205535e87dd7afe40f0eb71337ac22
sha1
71bc2f2a25ca575f01344a1db962ddcc2249f8df
sha256
56eb33001559fa628fe4eccbd026635e6247455093a8979d6e61db7a358bcfd7
<?php
/**
 * Joomla! Content Management System
 *
 * @copyright  Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
 * @license    GNU General Public License version 2 or later; see LICENSE
 */

namespace Joomla\CMS\Error\Renderer;

defined('JPATH_PLATFORM') or die;

use Joomla\CMS\Error\AbstractRenderer;

/**
 * JSON error page renderer
 *
 * @since  4.0
 */
class JsonRenderer extends AbstractRenderer
{
	/**
	 * The format (type) of the error page
	 *
	 * @var    string
	 * @since  4.0
	 */
	protected $type = 'json';

	/**
	 * Render the error page for the given object
	 *
	 * @param   \Throwable  $error  The error object to be rendered
	 *
	 * @return  string
	 *
	 * @since   4.0
	 */
	public function render(\Throwable $error): string
	{
		// Create our data object to be rendered
		$data = [
			'error'   => true,
			'code'    => $error->getCode(),
			'message' => $error->getMessage(),
		];

		// Include the stack trace if in debug mode
		if (JDEBUG)
		{
			$data['trace'] = $error->getTraceAsString();
		}

		// Push the data object into the document
		$this->getDocument()->setBuffer(json_encode($data));

		if (ob_get_contents())
		{
			ob_end_clean();
		}

		return $this->getDocument()->render();
	}
}

The same content is in 5 releases, Joomla 4.0.0-alpha7 to 4.0.0-alpha11. See them all, or every version of this file.