Skip to content

Commit 2c0a540

Browse files
author
arp
committed
temp
1 parent a3024e8 commit 2c0a540

File tree

4 files changed

+104
-37
lines changed

4 files changed

+104
-37
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
],
2222
"require" : {
2323
"php" : ">=7.0",
24-
"mouf/mvc.splash-common": "^8.4",
24+
"mouf/mvc.splash-common": "^9.0",
2525
"zendframework/zend-stratigility": "^3.0",
2626
"mouf/mouf": "~2.0.0"
2727
},
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace Mouf\Mvc\Splash;
4+
5+
use Psr\Http\Message\ResponseInterface;
6+
use Psr\Http\Message\ServerRequestInterface;
7+
use Psr\Http\Server\MiddlewareInterface;
8+
use Psr\Http\Server\RequestHandlerInterface;
9+
10+
/**
11+
* A middleware used to conditionally redirect to other middleware(s)
12+
*
13+
* Class ConditionMiddleware
14+
* @package Mouf\Mvc\Splash
15+
*/
16+
class ConditionMiddleware implements MiddlewareInterface{
17+
18+
/**
19+
* @var callable
20+
*/
21+
private $condition;
22+
/**
23+
* @var MiddlewareInterface
24+
*/
25+
private $ifMiddleware;
26+
/**
27+
* @var MiddlewareInterface
28+
*/
29+
private $elseMiddleware;
30+
31+
public function __construct(callable $condition, MiddlewareInterface $ifMiddleware, MiddlewareInterface $elseMiddleware = null)
32+
{
33+
$this->condition = $condition;
34+
$this->ifMiddleware = $ifMiddleware;
35+
$this->elseMiddleware = $elseMiddleware;
36+
}
37+
38+
/**
39+
* Process an incoming server request and return a response, optionally delegating
40+
* response creation to a handler.
41+
*/
42+
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
43+
{
44+
if(($this->condition)()) {
45+
$this->ifMiddleware->process($request, $handler);
46+
} else if($this->elseMiddleware) {
47+
$this->elseMiddleware->process($request, $handler);
48+
} else {
49+
$handler->handle($request);
50+
}
51+
}
52+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
}

src/Mouf/Mvc/Splash/SplashMiddleware.php

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)