PHP code example of webiik / middleware

1. Go to this page and download the library: Download webiik/middleware 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/ */

    

webiik / middleware example snippets


$middleware = new \Webiik\Middleware\Middleware($container, $data);
$middleware->add('MwTest:run', ['foo' => 'bar']);
$middleware->run();

class MwTest
{
    public function run(\Webiik\Data\Data $data, callable $next)
    {
        // Get middleware data
        $mwData = $data->getAll(); // Array([foo] => [bar])
         
        // Change middleware data 
        $data->set('foo', 'foo');
        
        // Launch next middleware
        $next();
        
        // Continue current middlware...
    }
}

add(string $controller, $data = []): void

$middleware->add('MwTest:run');

run(): void

$middleware->run();