Download the PHP package felixdorn/flash without Composer
On this page you can find all versions of the php package felixdorn/flash. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download felixdorn/flash
More information about felixdorn/flash
Files in felixdorn/flash
Package flash
Short Description Framework agnostic flash notifications for PHP 7.3+
License MIT
Informations about the package flash
Flash
- Extensible
- Fully tested and easily testable
- Allow functional use
- Support templates
Getting started
Before using Flash
, you need a DriverInterface and a template.
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
Rendering
Custom types
Clear messages
Enabling & Disabling
Drivers
There is only 2 but it's easy to implement a new one (PR appreciated :p).
- ArrayDriver Driver that should only be used for testing purpose.
- SessionDriver 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 session.
A driver must implement these 3 methods :
- clear(): self
- push(FlashData $data): self
- all(string $type = 'all'): array
The clear method
This is the simple one. It should clear any flash pushed.
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
This one should if $type = 'all'
return every flash pushed formatted like this :
If the $type
is something else then, it should return an array with only the flash inside this type.
Templates
- BootstrapTemplate
- BulmaTemplate
- Semantic2Template
- SpectreTemplate
- TestableTemplate
- NullTemplate
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
You can also set it when constructing the Flash object
Template using a string
This one is the most basic, but also the most useful.
So, if you flash an success Hello! flash. It will output
Template using a callable
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
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
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.