PHP code example of neoflow / flash

1. Go to this page and download the library: Download neoflow/flash library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

neoflow / flash example snippets


use Neoflow\Flash\Flash;
use Neoflow\Flash\FlashInterface;
use Neoflow\Flash\Middleware\FlashMiddleware;
use Psr\Container\ContainerInterface;

return [
    // ...
    FlashInterface::class => function () {
        $key = '_flash'; // Key as identifier of the values in the storage
        return new Flash($key);
    },
    FlashMiddleware::class => function (ContainerInterface $container) {
        $flash = $container->get(FlashInterface::class);
        return new FlashMiddleware($flash);
    },
    // ...
];

use Neoflow\Flash\Middleware\FlashMiddleware;

$app->add(FlashMiddleware::class);

$app->add(function ($request, $handler) use ($container) {
    $storage = [ 
        // Your custom storage of the values
    ];
    $container->get(FlashInterface::class)->load($storage);
    return $handler->handle($request);
});

use Neoflow\Flash\Flash;
use Neoflow\Flash\FlashInterface;

return [
    // ...
    FlashInterface::class => function () {
        $key = '_flash'; // Key as identifier of the values in the storage
        $storage = [
            // Your custom storage of the values
        ];
        return new Flash($key, $storage);
    },
    // ...
];

// Set a value by key for the next request.
$key = 'key'; // Key as identifier of the value
$flash = $flash->set($key, 'Your custom value');

// Get value by key, set for current request.
$default = null; // Default value, when value doesn't exists or is empty (default: null)
$value = $flash->get($key, $default);

// Check whether value by key for current request exists.
$exists = $flash->has($key);

// Count number of values for current request.
$numberOfValues = $flash->count();

// Clear values of current and next request.
$flash = $flash->clear();

// Keep current values for next request. Existing values will be overwritten.
$flash = $flash->keep(); 

// Load values from storage as reference.
$storage = [
    '_flash' => []
];
$flash = $flash->load($storage);

// Get values set for next request.
$nextValues = $flash->getNext();

// Set values for next request. Existing values will be overwritten.
$flash = $flash->setNext([
    'key1' => 'value1'
]);

// Get values set for current request.
$currentValues = $flash->getCurrent();

// Set values for current request. Existing values will be overwritten.
$flash = $flash->setCurrent([
    'key1' => 'value1'
]);