/var/www/vhosts/ihelp.ro/httpdocs/vendor/cakephp/cakephp/src/View
Edit: /var/www/vhosts/ihelp.ro/httpdocs/vendor/cakephp/cakephp/src/View/SerializedView.php (3690B)
*/
protected $_defaultConfig = [
'serialize' => null,
];
/**
* @inheritDoc
*/
public function initialize(): void
{
parent::initialize();
if ($this->_responseType) {
$response = $this->getResponse()->withType($this->_responseType);
$this->setResponse($response);
}
}
/**
* Load helpers only if serialization is disabled.
*
* @return $this
*/
public function loadHelpers()
{
if (!$this->getConfig('serialize')) {
parent::loadHelpers();
}
return $this;
}
/**
* Serialize view vars.
*
* @param array|string $serialize The name(s) of the view variable(s) that
* need(s) to be serialized
* @return string The serialized data.
*/
abstract protected function _serialize($serialize): string;
/**
* Render view template or return serialized data.
*
* @param string|null $template The template being rendered.
* @param string|false|null $layout The layout being rendered.
* @return string The rendered view.
* @throws \Cake\View\Exception\SerializationFailureException When serialization fails.
*/
public function render(?string $template = null, $layout = null): string
{
$serialize = $this->getConfig('serialize', false);
if ($serialize === true) {
$options = array_map(
function ($v) {
return '_' . $v;
},
array_keys($this->_defaultConfig)
);
$serialize = array_diff(
array_keys($this->viewVars),
$options
);
}
if ($serialize !== false) {
try {
return $this->_serialize($serialize);
} catch (Exception | TypeError $e) {
throw new SerializationFailureException(
'Serialization of View data failed.',
null,
$e
);
}
}
return parent::render($template, false);
}
}