krubio / perfect-flash-bs-5
SOLID Compliant Session Based Flash Messaging - Bootstrap 5
Requires
- php: >=8.1.0
- krubio/perfect-session: ^0.1.0
Requires (Dev)
- codeception/codeception: ^5.0
- codeception/module-asserts: *
- codeception/module-phpbrowser: *
- nunomaduro/phpinsights: ^2.8
- phpstan/phpstan: ^1.10
- vimeo/psalm: ^5.12
This package is auto-updated.
Last update: 2024-11-10 04:22:38 UTC
README
Bootstrap5FlashMessage
Description
Bootstrap5FlashMessage
is a PHP class that provides a simple and effective way to display flash messages in a web application. It uses Bootstrap 5 for styling and allows for optional icons and dismissible alerts.
Requirements
- PHP 8.0 or higher
- Bootstrap 5.3 or higher
Installation
Include the Bootstrap5FlashMessage
class in your project.
Usage
Initialization
First, you need to inject a session object that implements SessionInterface
and an array of messages into the constructor.
use PerfectApp\Session\SessionInterface; use PerfectApp\Bootstrap5FlashMessage; $session = new Session(); // This should implement SessionInterface $messages = [ 'success' => [ 'insert' => 'Record Inserted' ], 'danger' => [ 'failed_login' => 'Invalid Login' ] ]; $flash = new Bootstrap5FlashMessage($session, $messages);
Adding a Message
To add a flash message, use the addMessage
method.
$flash->addMessage('success', 'insert');
You can also add an optional icon and make the alert dismissible.
$flash->addMessage('danger', 'failed_login', 'bi-x-circle', true);
Displaying Messages
To display all the flash messages, use the displayMessages
method.
$flash->displayMessages();
This will output Bootstrap 5 styled alerts.
Testing
Run the following command to execute the unit tests and ensure 100% code coverage:
php vendor/bin/codecept run --coverage --coverage-html --coverage-xml
License
This project is licensed under the MIT License.