krubio/perfect-flash-bs-5

SOLID Compliant Session Based Flash Messaging - Bootstrap 5

v0.1.0 2023-10-10 01:52 UTC

This package is auto-updated.

Last update: 2024-11-10 04:22:38 UTC


README

codecov

Scrutinizer Code Quality Code Coverage Build Status Code Intelligence Status

Coverage Maintainability Rating Code Smells Technical Debt Quality Gate Status Reliability Rating

Duplicated Lines (%) Vulnerabilities Bugs Security Rating

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.