Berlioz FlashBag is a PHP library to manage flash messages to showed to the user.
Branch: master
Clone or download
Latest commit 7a7ac60 Jun 29, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Initial development May 24, 2018
tests
.gitattributes
.gitignore Initial development May 24, 2018
.travis.yml Initial development May 24, 2018
CHANGELOG.md Initial development May 24, 2018
LICENSE Initial commit May 24, 2018
README.md Update README.md Jun 29, 2018
composer.json
composer.lock
phpunit.xml.dist Initial development May 24, 2018

README.md

Berlioz FlashBag

Latest Version Software license Build Status Quality Grade Total Downloads

Berlioz FlashBag is a PHP library to manage flash messages to showed to the user.

Installation

Composer

You can install Berlioz FlashBag with Composer, it's the recommended installation.

$ composer require berlioz/flash-bag

Dependencies

  • PHP >= 7.1

Usage

All messages are stored in session of user. So you be able to get the messages after a reload of page or redirect. When you got the messages, they are deleted on the stack and no longer available.

Add message

It's very simple to add messages:

$flashBag = new FlashBag;
$flashBag->add(FlashBag::TYPE_SUCCESS, 'Message success')
         ->add(FlashBag::TYPE_INFO, 'Second message');

Some default types are available in constants:

FlashBag::TYPE_INFO = 'info';
FlashBag::TYPE_SUCCESS = 'success';
FlashBag::TYPE_WARNING = 'warning';
FlashBag::TYPE_ERROR = 'error';

Get message

To get message, it's also simple then add:

$flashBag = new FlashBag;
$successMessages = $flashBag->get('success');

foreach ($successMessages as $msg) {
    print $msg;
}

Get all messages

You can also get all messages in one time:

$flashBag = new FlashBag;
$allMessages = $flashBag->all();

foreach ($allMessages as $type => $messages) {
    foreach ($messages as $msg) {
        print sprintf('%s: %s', $type, $msg);
    }
}