|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Mouf\Mvc\Splash; |
| 4 | + |
| 5 | + |
| 6 | +use Psr\Http\Message\ResponseInterface; |
| 7 | +use Psr\Http\Message\ServerRequestInterface; |
| 8 | +use Psr\Http\Server\MiddlewareInterface; |
| 9 | +use Psr\Http\Server\RequestHandlerInterface; |
| 10 | +use Zend\Stratigility\MiddlewarePipe as ZendMiddleWarePipe; |
| 11 | + |
| 12 | +/** |
| 13 | + * The Splash MiddlewarePipe class is the root of the Splash framework.<br/> |
| 14 | + * It acts as a wrapper on Zend's MiddleWarePipe <br/> |
| 15 | + * It is in charge of binding an Url to a Controller.<br/> |
| 16 | + * There is one and only one instance of Splash per web application.<br/> |
| 17 | + * The name of the instance MUST be "splashMiddleware".<br/> |
| 18 | + * <br/> |
| 19 | + * The SplashMiddleware component has several ways to bind an URL to a Controller.<br/> |
| 20 | + * It can do so based on the @URL annotation, or based on the @Action annotation.<br/> |
| 21 | + * Check out the Splash documentation here: |
| 22 | + * <a href="https://github.com/thecodingmachine/mvc.splash/">https://github.com/thecodingmachine/mvc.splash/</a>. |
| 23 | + */ |
| 24 | +class MiddlewarePipe implements MiddlewareInterface |
| 25 | +{ |
| 26 | + private $zendPipe; |
| 27 | + |
| 28 | + /** |
| 29 | + * MiddlewarePipe constructor. |
| 30 | + * @param MiddlewareInterface[] $middlewares |
| 31 | + */ |
| 32 | + public function __construct(array $middlewares) |
| 33 | + { |
| 34 | + $this->zendPipe = new ZendMiddleWarePipe(); |
| 35 | + foreach ($middlewares as $middleware) { |
| 36 | + /** @var Router $router */ |
| 37 | + $this->zendPipe->pipe($middleware); |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * Process an incoming server request and return a response, optionally delegating |
| 43 | + * response creation to a handler. |
| 44 | + */ |
| 45 | + public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
| 46 | + { |
| 47 | + return $this->zendPipe->process($request, $handler); |
| 48 | + } |
| 49 | + |
| 50 | + |
| 51 | +} |
0 commit comments