for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Lit\Nimo\Traits;
use Interop\Http\Server\MiddlewareInterface;
use Lit\Nimo\Interfaces\RequestPredictionInterface;
use Lit\Nimo\MiddlewarePipe;
use Lit\Nimo\Middlewares\CatchMiddleware;
use Lit\Nimo\Middlewares\PredictionWrapperMiddleware;
trait MiddlewareTrait
{
use AttachToRequestTrait;
/**
* append $middleware after this one, return the new $middlewareStack
*
* @param $middleware
* @return MiddlewarePipe
*/
public function append(MiddlewareInterface $middleware): MiddlewarePipe
$stack = new MiddlewarePipe();
return $stack
->append($this)
->append($middleware);
}
* prepend $middleware before this one, return the new $middlewareStack
public function prepend(MiddlewareInterface $middleware): MiddlewarePipe
->prepend($this)
->prepend($middleware);
public function when(RequestPredictionInterface $requestPrediction): MiddlewareInterface
return new PredictionWrapperMiddleware($this, $requestPrediction);
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);