Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
],
"require" : {
"php" : ">=7.0",
"mouf/mvc.splash-common": "^8.2",
"zendframework/zend-stratigility": ">=2.0 <2.2",
"mouf/mvc.splash-common": "^10.0",
"zendframework/zend-stratigility": "^3.0",
"mouf/mouf": "~2.0.0"
},
"autoload" : {
Expand Down
53 changes: 53 additions & 0 deletions src/Mouf/Mvc/Splash/ConditionMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Mouf\Mvc\Splash;

use Mouf\Utils\Common\Condition\ToCondition;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

/**
* A middleware used to conditionally redirect to other middleware(s)
*
* Class ConditionMiddleware
* @package Mouf\Mvc\Splash
*/
class ConditionMiddleware implements MiddlewareInterface{

/**
* @var callable
*/
private $condition;
/**
* @var MiddlewareInterface
*/
private $ifMiddleware;
/**
* @var MiddlewareInterface
*/
private $elseMiddleware;

public function __construct(ToCondition $condition, MiddlewareInterface $ifMiddleware, MiddlewareInterface $elseMiddleware = null)
{
$this->condition = $condition;
$this->ifMiddleware = $ifMiddleware;
$this->elseMiddleware = $elseMiddleware;
}

/**
* Process an incoming server request and return a response, optionally delegating
* response creation to a handler.
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
if($this->condition->isOk()) {
return $this->ifMiddleware->process($request, $handler);
} else if($this->elseMiddleware) {
return $this->elseMiddleware->process($request, $handler);
} else {
return $handler->handle($request);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
namespace Mouf\Mvc\Splash\Controllers\Admin;

use Mouf\Composer\ClassNameMapper;
use Mouf\Mvc\Splash\Controllers\Controller;
use Mouf\Html\Template\TemplateInterface;
use Mouf\Html\HtmlElement\HtmlBlock;
use Mouf\Html\Utils\WebLibraryManager\WebLibrary;
use Mouf\Mvc\Splash\Services\SplashCreateControllerService;
use Mouf\Mvc\Splash\Services\SplashCreateControllerServiceException;
use Mouf\MoufManager;
use Mouf\Mvc\Splash\Controllers\Controller;
use TheCodingMachine\Splash\Services\SplashCreateControllerService;
use TheCodingMachine\Splash\Services\SplashCreateControllerServiceException;

/**
* A controller used to create controllers in Splash.
Expand Down
70 changes: 70 additions & 0 deletions src/Mouf/Mvc/Splash/MiddlewarePipe.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace Mouf\Mvc\Splash;


use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Stratigility\MiddlewarePipe as ZendMiddleWarePipe;

/**
* The Splash MiddlewarePipe class is the root of the Splash framework.<br/>
* It acts as a wrapper on Zend's MiddleWarePipe <br/>
* It is in charge of binding an Url to a Controller.<br/>
* There is one and only one instance of Splash per web application.<br/>
* The name of the instance MUST be "splashMiddleware".<br/>
* <br/>
* The SplashMiddleware component has several ways to bind an URL to a Controller.<br/>
* It can do so based on the @URL annotation, or based on the @Action annotation.<br/>
* Check out the Splash documentation here:
* <a href="https://github.com/thecodingmachine/mvc.splash/">https://github.com/thecodingmachine/mvc.splash/</a>.
*/
class MiddlewarePipe implements MiddlewareInterface, RequestHandlerInterface
{
private $zendPipe;

/**
* MiddlewarePipe constructor.
* @param MiddlewareInterface[] $middlewares
*/
public function __construct(array $middlewares)
{
$this->zendPipe = new ZendMiddleWarePipe();
foreach ($middlewares as $middleware) {
/** @var Router $router */
$this->zendPipe->pipe($middleware);
}
}

/**
* Process an incoming server request and return a response, optionally delegating
* response creation to a handler.
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
return $this->zendPipe->process($request, $handler);
}

/**
* Handle an incoming request.
*
* Attempts to handle an incoming request by doing the following:
*
* - Cloning itself, to produce a request handler.
* - Dequeuing the first middleware in the cloned handler.
* - Processing the first middleware using the request and the cloned handler.
*
* If the pipeline is empty at the time this method is invoked, it will
* raise an exception.
*
* @throws Exception\EmptyPipelineException if no middleware is present in
* the instance in order to process the request.
*/
public function handle(ServerRequestInterface $request) : ResponseInterface
{
return $this->zendPipe->handle($request);
}

}
77 changes: 0 additions & 77 deletions src/Mouf/Mvc/Splash/Routers/Router.php

This file was deleted.

39 changes: 0 additions & 39 deletions src/Mouf/Mvc/Splash/Routers/RouterInterface.php

This file was deleted.

36 changes: 0 additions & 36 deletions src/Mouf/Mvc/Splash/SplashMiddleware.php

This file was deleted.