pipe Pipe — helper in your project for the integration of Middleware

Helper in your project for the integration of middleware

https://github.com/petrgrishin/pipe

Example of use Pipe
<?php
use PetrGrishin\Pipe\Pipe;

// Class name
$accessFiltres = [
    AccessFilterMiddleware::class,
];

// Or class name with constructor arguments
$accessFiltres = [
    [AccessFilterMiddleware::class, $paramMiddleware],
];

// Or closure function
$accessFiltres = [
    function (Request $request, Responce $response, Closure $next) {
        return $next($request, $response);
    }
];

// Start the process
Pipe::create($request, $response)
    ->through($accessFiltres)
    ->through($XSSFiltres)
    ->then(function (Request $request, Responce $response) {
        $response->runController($request);
    });
Example middleware
<?php
class AccessFilterMiddleware {
    protected $paramMiddleware;
    
    public function __construct($paramMiddleware = null) {
        $this->paramMiddleware = $paramMiddleware;
    }

    public function __invoke(Request $request, Responce $response, Closure $next) {
        if ($request->isPost()) {
            $response->addError('Post is forbidden');
            return false;
        }
        return $next($request, $response);
    }
}
1 0
1 follower
111 downloads
Yii Version: all
License: MIT
Category: Networking
Developed by: Petr.Grishin
Created on: Feb 19, 2015
Last updated: 3 years ago

Downloads

show all

Related Extensions