/var/www/vhosts/ihelp.ro/_OLD/vendor/cakephp/cakephp/src/Controller/Component
Edit: /var/www/vhosts/ihelp.ro/_OLD/vendor/cakephp/cakephp/src/Controller/Component/FlashComponent.php (5744B)
'flash',
'element' => 'default',
'params' => [],
'clear' => false,
'duplicate' => true,
];
/**
* Used to set a session variable that can be used to output messages in the view.
* If you make consecutive calls to this method, the messages will stack (if they are
* set with the same flash key)
*
* In your controller: $this->Flash->set('This has been saved');
*
* ### Options:
*
* - `key` The key to set under the session's Flash key
* - `element` The element used to render the flash message. Default to 'default'.
* - `params` An array of variables to make available when using an element
* - `clear` A bool stating if the current stack should be cleared to start a new one
* - `escape` Set to false to allow templates to print out HTML content
*
* @param string|\Throwable $message Message to be flashed. If an instance
* of \Throwable the throwable message will be used and code will be set
* in params.
* @param array $options An array of options
* @return void
*/
public function set($message, array $options = []): void
{
$options += (array)$this->getConfig();
if ($message instanceof Throwable) {
if (!isset($options['params']['code'])) {
$options['params']['code'] = $message->getCode();
}
$message = $message->getMessage();
}
if (isset($options['escape']) && !isset($options['params']['escape'])) {
$options['params']['escape'] = $options['escape'];
}
[$plugin, $element] = pluginSplit($options['element']);
if ($plugin) {
$options['element'] = $plugin . '.flash/' . $element;
} else {
$options['element'] = 'flash/' . $element;
}
$messages = [];
if (!$options['clear']) {
$messages = (array)$this->getSession()->read('Flash.' . $options['key']);
}
if (!$options['duplicate']) {
foreach ($messages as $existingMessage) {
if ($existingMessage['message'] === $message) {
return;
}
}
}
$messages[] = [
'message' => $message,
'key' => $options['key'],
'element' => $options['element'],
'params' => $options['params'],
];
$this->getSession()->write('Flash.' . $options['key'], $messages);
}
/**
* Magic method for verbose flash methods based on element names.
*
* For example: $this->Flash->success('My message') would use the
* `success.php` element under `templates/element/flash/` for rendering the
* flash message.
*
* If you make consecutive calls to this method, the messages will stack (if they are
* set with the same flash key)
*
* Note that the parameter `element` will be always overridden. In order to call a
* specific element from a plugin, you should set the `plugin` option in $args.
*
* For example: `$this->Flash->warning('My message', ['plugin' => 'PluginName'])` would
* use the `warning.php` element under `plugins/PluginName/templates/element/flash/` for
* rendering the flash message.
*
* @param string $name Element name to use.
* @param array $args Parameters to pass when calling `FlashComponent::set()`.
* @return void
* @throws \Cake\Http\Exception\InternalErrorException If missing the flash message.
*/
public function __call(string $name, array $args)
{
$element = Inflector::underscore($name);
if (count($args) < 1) {
throw new InternalErrorException('Flash message missing.');
}
$options = ['element' => $element];
if (!empty($args[1])) {
if (!empty($args[1]['plugin'])) {
$options = ['element' => $args[1]['plugin'] . '.' . $element];
unset($args[1]['plugin']);
}
$options += (array)$args[1];
}
$this->set($args[0], $options);
}
/**
* Returns current session object from a controller request.
*
* @return \Cake\Http\Session
*/
protected function getSession(): Session
{
return $this->getController()->getRequest()->getSession();
}
}