- md5
- 30df060f7fa8e0a3dd42e1f41afbddb2
- sha1
- 2cda68f15427472e6e3177e3676e5248775693fa
- sha256
- 595cf1a83d67d68be58c4435b674d853e0bf737f65845f0054d2053e6bcd48b8
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
<?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\MVC\View;
\defined('JPATH_PLATFORM') or die;
/**
* Base class for a Joomla Json View
*
* Class holding methods for displaying presentation data.
*
* @since 4.0.0
*/
class JsonView extends AbstractView
{
/**
* The base path of the view
*
* @var string
* @since 4.0.0
*/
protected $_basePath = null;
/**
* Charset to use in escaping mechanisms; defaults to urf8 (UTF-8)
*
* @var string
* @since 4.0.0
*/
protected $_charset = 'UTF-8';
/**
* The output of the view.
*
* @var array
* @since 4.0.0
*/
protected $_output = array();
/**
* Constructor
*
* @param array $config A named configuration array for object construction.
* name: the name (optional) of the view (defaults to the view class name suffix).
* charset: the character set to use for display
* escape: the name (optional) of the function to use for escaping strings
* base_path: the parent path (optional) of the views directory (defaults to the component folder)
* template_plath: the path (optional) of the layout directory (defaults to base_path + /views/ + view name
* helper_path: the path (optional) of the helper files (defaults to base_path + /helpers/)
* layout: the layout (optional) to use to display the view
*
* @since 4.0.0
*/
public function __construct($config = array())
{
parent::__construct($config);
// Set the charset (used by the variable escaping functions)
if (\array_key_exists('charset', $config))
{
@trigger_error(
'Setting a custom charset for escaping is deprecated. Override \JViewLegacy::escape() instead.',
E_USER_DEPRECATED
);
$this->_charset = $config['charset'];
}
// Set a base path for use by the view
if (\array_key_exists('base_path', $config))
{
$this->_basePath = $config['base_path'];
}
else
{
$this->_basePath = JPATH_COMPONENT;
}
}
/**
* Execute and display a template script.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return void
*
* @since 4.0.0
*/
public function display($tpl = null)
{
// Serializing the output
$result = json_encode($this->_output);
// Pushing output to the document
$this->document->setBuffer($result);
}
}
The same content is in 23 releases, Joomla 4.1.0-beta2 to 4.2.0-beta2. See them all, or every version of this file.