PHPackages                             felixdorn/flash - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. felixdorn/flash

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

felixdorn/flash
===============

Framework agnostic flash notifications for PHP 7.3+

3.0.0(4y ago)7552MITPHPPHP ^8

Since Sep 27Pushed 4y ago2 watchersCompare

[ Source](https://github.com/felixdorn/flash)[ Packagist](https://packagist.org/packages/felixdorn/flash)[ RSS](/packages/felixdorn-flash/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (6)Dependencies (3)Versions (7)Used By (0)

[![Library logo](art/logo.png)](art/logo.png)

Flash
=====

[](#flash)

[![Packagist Version](https://camo.githubusercontent.com/a21157b709bd966ba410081efeb373e524c2e0178d6f93a9cbabc27646e15f70/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f66656c6978646f726e2f666c617368)](https://camo.githubusercontent.com/a21157b709bd966ba410081efeb373e524c2e0178d6f93a9cbabc27646e15f70/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f66656c6978646f726e2f666c617368)[![Build Status](https://camo.githubusercontent.com/56be53711e72cacefc41c532492f86b9d748c4187e3cfd0bbd8cf7e10909ba9c/68747470733a2f2f7472617669732d63692e6f72672f66656c6978646f726e2f666c6173682e7376673f6272616e63683d7263322e302e30)](https://travis-ci.org/felixdorn/flash)[![codecov](https://camo.githubusercontent.com/de3bd62f8a9fd842e3ddbfe951de752b1f80bdfc39de8c449532008b902b3ec3/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f66656c6978646f726e2f666c617368)](https://codecov.io/gh/felixdorn/flash)

- Extensible
- Fully tested and easily testable
- Allow functional use
- Support templates

Getting started
---------------

[](#getting-started)

```
composer require felixdorn/flash
```

Before using `Flash`, you need a [Driver](#drivers) that implements the [DriverInterface](src/Drivers/DriverInterface.php) and a template.

```
use Felix\Flash\Drivers\SessionDriver;
use Felix\Flash\Flash;
use Felix\Flash\Templates\SpectreTemplate;

$driver = new SessionDriver([
    // session_start options
    // see https://www.php.net/manual/fr/function.session-start.php
]);

// A random template
$template = new SpectreTemplate();

$flash = new Flash($driver, $template);
```

Usage
-----

[](#usage)

These are common examples to work with flash.

> In these example, i assume that you have already made the setup and have a working Flash instance.

### Flashing

[](#flashing)

```
$flash->success('message');

$flash->warning('message');

$flash->error('message');

$flash->info('message');

$flash->flash('type', 'message');
```

### Rendering

[](#rendering)

```
$flash->success('message');
$flash->warning('message1');

$flash->render(); // implicitly it's $flash->render('all')

// render 'message' and 'message1' using the defined template

$flash->render('success');

// render 'message' but not 'message1'
```

### Custom types

[](#custom-types)

```
$flash->message('really-important', 'In movie gone in 60 seconds, things are gone in 60 seconds');

$flash->render(); // will also render `really-important` as a normal type.

$flash->render('really-important'); // will render `really-important` flashes using the default template
```

### Clear messages

[](#clear-messages)

```
$flash->success('Cool!');

$flash->clear('success'); // delete every success flash using the Driver

$flash->render(); // Won't render anything

$flash->success('Cool!');
$flash->error('Uhhhh.');

$flash->clear(); // Clear every flashes

$flash->render(); // Won't render anything
```

### Enabling &amp; Disabling

[](#enabling--disabling)

```
$flash->error('Bad thing.');

$flash->disable();
// NOTE: Here, when disabling, you can still clear or render

$flash->success('Good thing');

$flash->enable();

$flash->render('all'); // 'all' is optional, it's the default value

// Here, only 'Bad thing.' will be rendered.
```

Drivers
-------

[](#drivers)

There is only 2 but it's easy to implement a new one (PR appreciated :p).

- [ArrayDriver](src/Drivers/ArrayDriver.php) Driver that should only be used for testing purpose.
- [SessionDriver](src/Drivers/SessionDriver.php) Driver to work with the most common implementation of session in PHP.

Let's dive into what they do, and how they work. This part is useful if you want to create your own, otherwise jump to the [next](#templates) session.

A driver must implement these 3 methods :

- clear(): self
- push(FlashData $data): self
- all(string $type = 'all'): array

### The clear method

[](#the-clear-method)

This is the simple one. It should clear any flash pushed.

### The push method

[](#the-push-method)

This one receive a FlashData with the type of flash and the value and should register it to be able to get it back.

### The all method

[](#the-all-method)

This one should if `$type = 'all'` return every flash pushed formatted like this :

```
return [
    '{someType}' => [
        'someFlash'
        // ...
    ],
    // ...
];
```

If the `$type` is something else then, it should return an array with only the flash inside this type.

```
return [
    'someFlash'
];
```

Templates
---------

[](#templates)

- [BootstrapTemplate](src/Templates/BootstrapTemplate.php)
- [BulmaTemplate](src/Templates/BulmaTemplate.php)
- [Semantic2Template](src/Templates/SpectreTemplate.php)
- [SpectreTemplate](src/Templates/SpectreTemplate.php)
- [TestableTemplate](src/Templates/TestableTemplate.php)
- [NullTemplate](src/Templates/NullTemplate.php)

> TestableTemplate just returns `{type}: {value}`, so it's easier to test if a flash worked well instead of typing all of the boring HTML.

### Registering a template

[](#registering-a-template)

```
$flash->setTemplate(...);
```

> You can also set it when constructing the *Flash* object

### Template using a string

[](#template-using-a-string)

This one is the most basic, but also the most useful.

```
{flash}

```

So, if you flash an success Hello! flash. It will output

```
Hello!

```

### Template using a callable

[](#template-using-a-callable)

```
function (string $type, string $message): string {
    return sprintf('%s', $type, $message);
}
```

In this case, you don't need a callable, and you could just use a string based template but this is how it works.

### Template using TemplateInterface

[](#template-using-templateinterface)

```
use Felix\Flash\Templates\TemplateInterface;

class MyTemplate implements TemplateInterface {
    public function toHtml(string $type,string $message){
        return sprintf('%s', $type, $message);
    }
}
```

In this case, you don't need a Template class, and you could just use a string based template but this is how it works.

Testing
-------

[](#testing)

```
composer test

```

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Félix Dorn](https://felixdorn.fr)

### Contributors

[](#contributors)

- [Grafikart](https://github.com/grafikart)

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 95.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~170 days

Recently: every ~204 days

Total

6

Last Release

1569d ago

Major Versions

1.1.2 → 2.0.02020-02-19

2.0.0 → 3.0.02022-01-27

PHP version history (3 changes)1.1.0PHP ^7.1

2.0.0PHP ^7.3

3.0.0PHP ^8

### Community

Maintainers

![](https://www.gravatar.com/avatar/eeca3822ab1a1281e77e0c4f7bdb671c840417def9884107629952224ce42eb0?d=identicon)[felixdorn](/maintainers/felixdorn)

---

Top Contributors

[![felixdorn](https://avatars.githubusercontent.com/u/55788595?v=4)](https://github.com/felixdorn "felixdorn (42 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![Grafikart](https://avatars.githubusercontent.com/u/395137?v=4)](https://github.com/Grafikart "Grafikart (1 commits)")

---

Tags

flashpackagephpsession

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/felixdorn-flash/health.svg)

```
[![Health](https://phpackages.com/badges/felixdorn-flash/health.svg)](https://phpackages.com/packages/felixdorn-flash)
```

###  Alternatives

[yireo/magento2-replace-all

Remove various packages from Magento

1303.7k](/packages/yireo-magento2-replace-all)[davist11/craft-reroute

Manage 301/302 redirects in the control panel.

607.1k](/packages/davist11-craft-reroute)[presseddigital/colorit

A slick color picker fieldtype plugin for the Craft CMS 3 control panel.

2132.1k](/packages/presseddigital-colorit)[hhxsv5/php-coroutine

A lightweight library to implement coroutine by yield &amp; Generator.

272.1k](/packages/hhxsv5-php-coroutine)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
