2017 © Pedro Peláez
 

library flashy

A wrapper around Symfony's HTTP foundation session flashbag to handle messages and form flash data

image

volnix/flashy

A wrapper around Symfony's HTTP foundation session flashbag to handle messages and form flash data

  • Monday, June 19, 2017
  • by volnix
  • Repository
  • 2 Watchers
  • 0 Stars
  • 100 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 12 Versions
  • 0 % Grown

The README.md

Flashy

Simple wrapper around Symfony's Session flashbag., (*1)

Build Status Coverage Status Total Downloads Latest Stable Version, (*2)

There are two pieces to flashy: Prefill Data and Messages., (*3)

Prefill Data

Often you will want to pre-fill form data from the last request when there are errors with user input. Flashy will accept input from any source, whether it was from POST/GET or a generated array. It is using Symfony's AutoExpireFlashBag container so data is cleared after every request whether it is read or not., (*4)

To set the form data is done by calling the set method:, (*5)

use Symfony\Component\HttpFoundation\Request;
use Volnix\Flashy\FormData;

$request = Request::createFromGlobals();
$form_data = new FormData;
$form_data->set($request->query->all());

You would then call get to retrieve data, optionally passing a default value to use if the key is not set., (*6)

use Volnix\Flashy\FormData;

$form_data = new FormData;
$form_data->set(['foo' => 'bar']);

echo $form_data->get('foo'); // bar
echo $form_data->get('bim', 'baz'); // baz

To empty the form data storage, call the clear function:, (*7)

use Volnix\Flashy\FormData;

$form_data = new FormData;
$form_data->set(['foo' => 'bar']);

echo $form_data->set('foo'); // bar

$form_data->clear();
echo $form_data->get('foo', 'baz'); // baz

Messages

The Messages class will make handling flash messages a breeze. It is loosely tied to Bootstrap 3 for its alert markup, but this can easily be overridden. It is also using Symfony's AutoExpireFlashBag container., (*8)

The __call magic method is used to allow any type of messages for maximum portability., (*9)

To set a type of message, you may call any function, passing in a string or an array of messages, e.g.:, (*10)

use Volnix\Flashy\Messages;

$messages = new Messages;
$messages->error('Oh no!');
$messages->info(['Message one', 'Message two']);

You may also set messages as an array of [type => messages], e.g.:, (*11)

use Volnix\Flashy\Messages;

$messages = new Messages;
$messages->setAsArray(['error' => 'foo');

To retrieve them as an array, use the get function (if not arg is passed, it will return all messages:, (*12)

use Volnix\Flashy\Messages;

$messages = new Messages;
$messages->error('Oh no!');
$messages->info(['Message one', 'Message two']);

foreach ($messages->get('error') as $error_message) {
    echo $error_message;
}

$all_messages = $messages->get();

The real magic happen when you call the getFormatted function:, (*13)

use Volnix\Flashy\Messages;

$messages = new Messages;
$messages->error('Oh no!');
$messages->info(['Message one', 'Message two']);

// print all the error messages:
echo $messages->getFormatted('error');

// print all the messages:
echo $messages->getFormatted();

Formatted messages are printed in the following markup:, (*14)

<div class="alert alert-danger">
    <ul>
        <li>Message one</li>
        <li>Message two</li>
    </ul>
</div>

To override the default Bootstrap alert syntax, pass an array of class overrides to the getFormatted function:, (*15)

use Volnix\Flashy\Messages;

$messages = new Messages;
$messages->error('Oh no!');

echo $messages->getFormatted('error', ['error' => 'bip']);

will yield:, (*16)

<div class="bip">
    <ul>
        <li>Oh no!</li>
    </ul>
</div>

The Messages class also supports nesting of messages, e.g.:, (*17)

use Volnix\Flashy\Messages;

$messages = new Messages;
$messages->error(['foo', 'bar' => ['bip', 'bap']]);

echo $messages->getFormatted('error');

will yield:, (*18)

<div class="alert alert-danger">
    <ul>
        <li>foo</li>
        <li>
            bar
            <ul>
                <li>bip</li>
                <li>bap</li>
            </ul>
        </li>
    </ul>
</div>

To empty the messages storage, call the clear function:, (*19)

use Volnix\Flashy\Messages;

$messages = new Messages;
$messages->set(['foo' => 'bar']);

echo $messages->get('foo'); // bar

$messages->clear();
echo $messages->get('foo', 'baz'); // baz

The Versions

19/06 2017

3.2.1

3.2.1.0 https://github.com/volnix/flashy

A wrapper around Symfony's HTTP foundation session flashbag to handle messages and form flash data

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nick Volgas

18/08 2014

dev-master

9999999-dev https://github.com/volnix/flashy

A wrapper around Symfony's HTTP foundation session flashbag to handle messages and form flash data

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nick Volgas

18/08 2014

3.2

3.2.0.0 https://github.com/volnix/flashy

A wrapper around Symfony's HTTP foundation session flashbag to handle messages and form flash data

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nick Volgas

13/06 2014

3.1

3.1.0.0 https://github.com/volnix/flashy

A wrapper around Symfony's HTTP foundation session flashbag to handle messages and form flash data

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nick Volgas

30/05 2014

3.0

3.0.0.0 https://github.com/volnix/flashy

A wrapper around Symfony's HTTP foundation session flashbag to handle messages and form flash data

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nick Volgas

29/05 2014

2.1

2.1.0.0 https://github.com/volnix/flashy

A wrapper around Symfony's HTTP foundation session flashbag to handle messages and form flash data

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nick Volgas

29/05 2014

2.0.1

2.0.1.0 https://github.com/volnix/flashy

A wrapper around Symfony's HTTP foundation session flashbag to handle messages and form flash data

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nick Volgas

29/05 2014

2.0

2.0.0.0 https://github.com/volnix/flashy

A wrapper around Symfony's HTTP foundation session flashbag to handle messages and form flash data

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nick Volgas

21/04 2014

1.2.1

1.2.1.0 https://github.com/volnix/flashy

A wrapper around Symfony's HTTP foundation session flashbag to handle messages and form flash data

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nick Volgas

04/04 2014

1.1.1

1.1.1.0 https://github.com/volnix/flashy

A wrapper around Symfony's HTTP foundation session flashbag to handle messages and form flash data

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nick Volgas

04/04 2014

1.1

1.1.0.0 https://github.com/volnix/flashy

A wrapper around Symfony's HTTP foundation session flashbag to handle messages and form flash data

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nick Volgas

04/04 2014

1.0

1.0.0.0 https://github.com/volnix/flashy

A wrapper around Symfony's HTTP foundation session flashbag to handle messages and form flash data

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nick Volgas