2017 © Pedro Peláez
 

library simple-flash

Easy, framework agnostic flash notifications for PHP.

image

tamtamchik/simple-flash

Easy, framework agnostic flash notifications for PHP.

  • Monday, July 10, 2017
  • by tamtamchik
  • Repository
  • 5 Watchers
  • 55 Stars
  • 9,452 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 4 Forks
  • 1 Open issues
  • 17 Versions
  • 11 % Grown

The README.md

Simple Flash Messages

Latest Version on Packagist ![Total Downloads][ico-downloads] ![Software License][ico-license] Build Status ![Coverage Status][ico-scrutinizer] Quality Score ![SensioLabsInsight][ico-insight], (*1)

Easy, framework-agnostic flash notifications for PHP. Inspired by laracasts/flash and plasticbrain/PHP-Flash-Messages. It supports multiple CSS frameworks out of the box:, (*2)

simple-flash, (*3)

[!NOTE] The documentation below is for version 3.x!
If you are looking the documentation for version 2.x look here.
If you are looking the documentation for version 1.x look here., (*4)

Install

Via Composer., (*5)

$ composer require tamtamchik/simple-flash

Inside your project make sure to start a session and load Composer autoload to make everything work., (*6)

````php message('Tea.'); // Static Flash::message('Earl Gray.'); // Function flash()->message('Hot!'); ``` Messages added by calling `message($message, $type = 'info')` method. In case of calling a function `flash()` you can pass `$message, $type` just to function like so: `flash('resistance is futile')`. Because any of creation types return `\Tamtamchik\SimpleFlash\Flash` instance, so you can always use chaining to add multiple messages. Shortcuts available for all types of base message types, also you can pass arrays as `$message`. ```php use function Tamtamchik\SimpleFlash\flash; flash()->error(['Invalid email!', 'Invalid username!']) ->warning('Warning message.') ->info('Info message.') ->success('Success message!'); ``` Out of the box library support 4 different types of messages: `error`, `warning`, `info`, `success`. ```html , (*7)

``` Rendering is simple: ```php use function Tamtamchik\SimpleFlash\flash; // Rendering specific type $output = flash()->display('error'); // Rendering all flash $output = flash()->display(); // Also rendering possible when you just read instance of \Tamtamchik\SimpleFlash\Flash object as a string (string) flash(); // or ... it's totally just for display, never do this in real life... warning('It is totally just for display, never do this in real life...'); // ... some other code ?>
= $flash; ?>

## Templates Using templates you can customize how flash messages will be rendered. Package comes with a set of templates for most popular CSS frameworks: ```php Templates::BASE; // Same as Templates::BOOTSTRAP Templates::BOOTSTRAP; // https://getbootstrap.com Templates::FOUNDATION; // https://get.foundation Templates::BULMA; // https://bulma.io Templates::MATERIALIZE; // https://materializecss.com Templates::TAILWIND; // https://tailwindcss.com Templates::PRIMER; // https://primer.style Templates::UIKIT; // https://getuikit.com Templates::SEMANTIC; // https://semantic-ui.com Templates::SPECTRE; // https://picturepan2.github.io/spectre Templates::HALFMOON; // https://www.gethalfmoon.com

Shortcuts

You cah pass template name as a second argument to display() function:, (*13)

use function Tamtamchik\SimpleFlash\flash;

flash()->success('Success message!');
...
// rendering with Halfmoon template using Templates::HALFMOON as a shortcut
echo flash()->display('success', Templates::HALFMOON);

Or you can use descriptive display functions:, (*14)

use function Tamtamchik\SimpleFlash\flash;

flash()->success('Success message!');
...
echo flash()->displayBootstrap();
echo flash()->displayFoundation();
echo flash()->displayBulma();
echo flash()->displayMaterialize();
echo flash()->displayTailwind();
echo flash()->displayPrimer();
echo flash()->displayUiKit();
echo flash()->displaySemantic();
echo flash()->displaySpectre();
echo flash()->displayHalfmoon();

Factory

Package comes with a set of templates for most popular CSS frameworks:, (*15)

This templates can be created using TemplateFactory that comes with package. All templates have aliases defined in Templates., (*16)

use Tamtamchik\SimpleFlash\Flash;
use Tamtamchik\SimpleFlash\TemplateFactory;
use Tamtamchik\SimpleFlash\Templates;

// get template from factory, e.g. template for Foundation
$template = TemplateFactory::create(Templates::FOUNDATION);

// passing template via function
flash('Info message using Foundation 6 template!', 'info', $template);

// passing to constructor
$flash = new Flash($template);

// using setTemplate function
$flash->setTemplate($template);

Creating templates

Template is basically any class that implements TemplateInterface. But to make it easy you can extend BaseTemplate, it already contains most of the functions., (*17)

Defining and using this sample class as template:, (*18)

use Tamtamchik\SimpleFlash\BaseTemplate;
use Tamtamchik\SimpleFlash\TemplateInterface;
use function Tamtamchik\SimpleFlash\flash;

class CustomTemplate extends BaseTemplate implements TemplateInterface
{
    protected $prefix  = '<li>'; // every line prefix
    protected $postfix = '</li>'; // every line postfix
    protected $wrapper = '

    %s
'; // wrapper over messages of same type /** * @param $messages - message text * @param $type - message type: success, info, warning, error * * @return string */ public function wrapMessages($messages, $type) { return sprintf($this->getWrapper(), $type, $messages); } } flash() ->setTemplate(new CustomTemplate) ->error(['Invalid email!', 'Invalid username!']) ->warning('Warning message.') ->info('Info message.') ->success('Success message!') ->display();

Will output following:, (*19)

<ul class="alert-error">
    <li>Invalid email!</li>
    <li>Invalid username!</li>
</ul>
<ul class="alert-warning">
    <li>Warning message.</li>
</ul>
<ul class="alert-info">
    <li>Info message.</li>
</ul>
<ul class="alert-success">
    <li>Success message!</li>
</ul>

Interface

Package provides TemplateInterface for Simple Flash templates., (*20)

Change log

Please see CHANGELOG for more information what has changed recently., (*21)

Testing

``` bash $ composer tests, (*22)


## Examples ``` bash $ composer examples

And then just visit http://localhost:8000, (*23)

Contributing

Please see CONTRIBUTING and CONDUCT for details., (*24)

Security

If you discover any security related issues, please email yuri.tam.tkachenko@gmail.com instead of using the issue tracker., (*25)

Credits

License

The MIT License (MIT). Please see License File for more information., (*26)

Buy Me A Coffee, (*27)

The Versions

10/07 2017

dev-master

9999999-dev http://github.com/tamtamchik/simple-flash

Easy, framework agnostic flash notifications for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

messages notifications flash agnostic

07/04 2017

1.2.x-dev

1.2.9999999.9999999-dev http://github.com/tamtamchik/simple-flash

Easy, framework agnostic flash notifications for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

messages notifications flash agnostic

05/04 2017

1.2.4

1.2.4.0 http://github.com/tamtamchik/simple-flash

Easy, framework agnostic flash notifications for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

messages notifications flash agnostic

21/12 2016

1.2.3

1.2.3.0 http://github.com/tamtamchik/simple-flash

Easy, framework agnostic flash notifications for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

messages notifications flash agnostic

10/05 2016

1.2.2

1.2.2.0 http://github.com/tamtamchik/simple-flash

Easy, framework agnostic flash notifications.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

messages notifications flash agnostic

25/04 2016

1.2.1

1.2.1.0 http://github.com/tamtamchik/simple-flash

Easy, framework agnostic flash notifications.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

messages notifications flash agnostic

31/03 2016

1.1.x-dev

1.1.9999999.9999999-dev http://github.com/tamtamchik/simple-flash

Easy, framework agnostic flash notifications.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

messages notifications flash agnostic

19/03 2016

1.2.0

1.2.0.0 http://github.com/tamtamchik/simple-flash

Easy, framework agnostic flash notifications.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

messages notifications flash agnostic

14/03 2016

1.1.1

1.1.1.0 http://github.com/tamtamchik/simple-flash

Easy, framework agnostic flash notifications.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

messages notifications flash agnostic

13/03 2016

1.1.0

1.1.0.0 http://github.com/tamtamchik/simple-flash

Easy, framework agnostic flash notifications.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

messages notifications flash agnostic

28/12 2015

1.0.x-dev

1.0.9999999.9999999-dev http://github.com/tamtamchik/simple-flash

Easy, framework agnostic flash notifications.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

messages notifications flash agnostic

20/12 2015

1.0.1

1.0.1.0 http://github.com/tamtamchik/simple-flash

Easy, framework agnostic flash notifications.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

messages notifications flash agnostic

14/08 2015

1.0.0

1.0.0.0 http://github.com/tamtamchik/simple-flash

Easy, framework agnostic flash notifications.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

messages notifications flash agnostic

30/05 2015

0.4.2

0.4.2.0 http://github.com/tamtamchik/simple-flash

Easy, framework agnostic flash notifications.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

messages notifications flash agnostic

29/05 2015

0.4.1

0.4.1.0 http://github.com/tamtamchik/simple-flash

Easy, framework agnostic flash notifications.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

messages notifications flash agnostic

28/05 2015

0.4.0

0.4.0.0 http://github.com/tamtamchik/simple-flash

Easy, framework agnostic flash notifications.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

messages notifications flash agnostic

28/05 2015

0.3.2

0.3.2.0 http://github.com/tamtamchik/simple-flash

Easy, framework agnostic flash notifications.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

messages notifications flash agnostic