for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php namespace Nimo\Traits;
use Interop\Http\Server\MiddlewareInterface;
use Nimo\MiddlewarePipe;
use Nimo\Middlewares\CatchMiddleware;
use Nimo\Middlewares\ConditionMiddleware;
trait MiddlewareTrait
{
use AttachToRequestTrait;
/**
* append $middleware after this one, return the new $middlewareStack
*
* @param $middleware
* @return MiddlewarePipe
*/
public function append($middleware): MiddlewarePipe
$stack = new MiddlewarePipe();
return $stack
->append($this)
->append($middleware);
}
* prepend $middleware before this one, return the new $middlewareStack
public function prepend($middleware): MiddlewarePipe
->prepend($this)
->prepend($middleware);
* wrap this middleware with $conditionCallback (skip this when the callback return falsy value)
* @param callable $conditionCallback ($req, $res, $next)
* @return ConditionMiddleware
public function when(callable $conditionCallback): MiddlewareInterface
return new ConditionMiddleware($conditionCallback, $this);
public function catch(callable $catcher, string $catchClass = \Throwable::class): MiddlewareInterface
Only declaring a single property per statement allows you to later on add doc comments more easily.
It is also recommended by PSR2, so it is a common style that many people expect.
return new CatchMiddleware($this, $catcher, $catchClass);