Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/berliozframework/flashbag
Berlioz FlashBag is a PHP library to manage flash messages to showed to the user.
https://github.com/berliozframework/flashbag
Last synced: about 1 month ago
JSON representation
Berlioz FlashBag is a PHP library to manage flash messages to showed to the user.
- Host: GitHub
- URL: https://github.com/berliozframework/flashbag
- Owner: BerliozFramework
- License: mit
- Created: 2018-05-24T08:09:14.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2021-09-06T20:29:37.000Z (over 3 years ago)
- Last Synced: 2024-11-16T23:34:35.653Z (about 1 month ago)
- Language: PHP
- Homepage:
- Size: 22.5 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Berlioz FlashBag
[![Latest Version](https://img.shields.io/packagist/v/berlioz/flash-bag.svg?style=flat-square)](https://github.com/BerliozFramework/FlashBag/releases)
[![Software license](https://img.shields.io/github/license/BerliozFramework/FlashBag.svg?style=flat-square)](https://github.com/BerliozFramework/FlashBag/blob/develop/LICENSE)
[![Build Status](https://img.shields.io/github/workflow/status/BerliozFramework/FlashBag/Tests/main.svg?style=flat-square)](https://github.com/BerliozFramework/FlashBag/actions/workflows/tests.yml?query=branch%3Amain)
[![Quality Grade](https://img.shields.io/codacy/grade/9f0ac8ab057549ce95d0dda7d29fa909/main.svg?style=flat-square)](https://www.codacy.com/manual/BerliozFramework/FlashBag)
[![Total Downloads](https://img.shields.io/packagist/dt/berlioz/flash-bag.svg?style=flat-square)](https://packagist.org/packages/berlioz/flash-bag)**Berlioz FlashBag** is a PHP library to manage flash messages to showed to the user.
## Installation
### Composer
You can install **Berlioz FlashBag** with [Composer](https://getcomposer.org/), it's the recommended installation.
```bash
$ composer require berlioz/flash-bag
```### Dependencies
* **PHP** ^7.1 || ^8.0
## 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:
```php
$flashBag = new FlashBag;
$flashBag
->add(FlashBag::TYPE_SUCCESS, 'Message success')
->add(FlashBag::TYPE_INFO, 'Second message')
->add(FlashBag::TYPE_INFO, 'Third message for %d %s', 3, 'persons');
```Some default types are available in constants:
```php
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:
```php
$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:
```php
$flashBag = new FlashBag;
$allMessages = $flashBag->all();foreach ($allMessages as $type => $messages) {
foreach ($messages as $msg) {
print sprintf('%s: %s', $type, $msg);
}
}
```