webiik / flash
The Flash provides multilingual flash notifications.
Requires
- php: >=7.2
- webiik/session: ^1
This package is auto-updated.
Last update: 2024-10-29 05:11:00 UTC
README
Flash
The Flash provides multilingual flash notifications.
Installation
composer require webiik/flash
Example
$flash = new \Webiik\Flash\Flash($session); $flash->addFlashCurrent('inf', 'Hello {name}', ['name' => 'Dolly']); $flash->addFlashNext('inf', 'Hello {name}', ['name' => 'Molly']); print_r($flash->getFlashes()); // Array ([inf] => Array ([0] => Hello Dolly ))
Next request:
$flash = new \Webiik\Flash\Flash($session); print_r($flash->getFlashes()); // Array ([inf] => Array ([0] => Hello Molly ))
Configuration
setLang
setLang(string $lang): void
setLang() sets current language of flash messages. The default value is en.
$flash->setLang('en');
Adding
addFlashCurrent
addFlashCurrent(string $type, string $message, array $context = []): void
addFlashCurrent() adds flash message in current language to be displayed in current request. $type represents custom type of message e.g. inf, err, ok. The message may contain {placeholders} which will be replaced with values from the $context array.
$flash->addFlashCurrent('inf', 'Hello {name}', ['name' => 'Dolly']);
addFlashNext
addFlashNext(string $type, string $message, array $context = []): void
addFlashNext() adds flash message in current language to be displayed in next request. $type represents custom type of message e.g. inf, err, ok. The message may contain {placeholders} which will be replaced with values from the $context array.
$flash->addFlashNext('inf', 'Hello {name}', ['name' => 'Molly']);
Getting
getFlashes
getFlashes(): array
getFlashes() returns array of all messages to be displayed in current request and language.
$flashMessages = $flash->getFlashes();