petrgrishin / pipe
Helper in your project for the integration of middleware
Installs: 2 314
Dependents: 1
Suggesters: 0
Security: 0
Stars: 9
Watchers: 5
Forks: 1
Open Issues: 0
Requires
- php: >=5.3.0
Requires (Dev)
This package is not auto-updated.
Last update: 2024-11-09 17:50:48 UTC
README
Helper in your project for the integration of middleware
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); } }