Skip to content

Commit bc7cea4

Browse files
authored
Merge pull request #5 from moufmouf/10.0
Migrating to 10.0
2 parents 97ee631 + bfbe7c7 commit bc7cea4

File tree

7 files changed

+128
-157
lines changed

7 files changed

+128
-157
lines changed

composer.json

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

src/Mouf/Mvc/Splash/Controllers/Admin/SplashCreateControllerController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
namespace Mouf\Mvc\Splash\Controllers\Admin;
44

55
use Mouf\Composer\ClassNameMapper;
6-
use Mouf\Mvc\Splash\Controllers\Controller;
76
use Mouf\Html\Template\TemplateInterface;
87
use Mouf\Html\HtmlElement\HtmlBlock;
98
use Mouf\Html\Utils\WebLibraryManager\WebLibrary;
10-
use Mouf\Mvc\Splash\Services\SplashCreateControllerService;
11-
use Mouf\Mvc\Splash\Services\SplashCreateControllerServiceException;
129
use Mouf\MoufManager;
10+
use Mouf\Mvc\Splash\Controllers\Controller;
11+
use TheCodingMachine\Splash\Services\SplashCreateControllerService;
12+
use TheCodingMachine\Splash\Services\SplashCreateControllerServiceException;
1313

1414
/**
1515
* A controller used to create controllers in Splash.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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, RequestHandlerInterface
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+
* Handle an incoming request.
52+
*
53+
* Attempts to handle an incoming request by doing the following:
54+
*
55+
* - Cloning itself, to produce a request handler.
56+
* - Dequeuing the first middleware in the cloned handler.
57+
* - Processing the first middleware using the request and the cloned handler.
58+
*
59+
* If the pipeline is empty at the time this method is invoked, it will
60+
* raise an exception.
61+
*
62+
* @throws Exception\EmptyPipelineException if no middleware is present in
63+
* the instance in order to process the request.
64+
*/
65+
public function handle(ServerRequestInterface $request) : ResponseInterface
66+
{
67+
return $this->zendPipe->handle($request);
68+
}
69+
70+
}

src/Mouf/Mvc/Splash/Routers/Router.php

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

src/Mouf/Mvc/Splash/Routers/RouterInterface.php

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

src/Mouf/Mvc/Splash/SplashMiddleware.php

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

0 commit comments

Comments
 (0)