Skip to content
Closed
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
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ language: php
php:
- 7.0
- 7.1
- 7.2

before_script:
- composer install --no-interaction

- mkdir -p build/logs
script:
- phpunit

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"container-interop/service-provider": "^0.4",
"thecodingmachine/common-factories": "^0.4",
"thecodingmachine/middleware-list-universal-module": "~1.0",
"http-interop/http-middleware": "^0.4"
"psr/http-server-middleware": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^5.0",
Expand Down
13 changes: 7 additions & 6 deletions src/Mouf/Mvc/Splash/Routers/CacheRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

namespace Mouf\Mvc\Splash\Routers;

use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Mouf\Utils\Cache\CacheInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Log\LoggerInterface;
use Mouf\Utils\Common\ConditionInterface\ConditionInterface;

//todo: delete or test
class CacheRouter implements MiddlewareInterface
{
/**
Expand Down Expand Up @@ -39,11 +40,11 @@ public function __construct(CacheInterface $cache, LoggerInterface $log, Conditi
* to the next middleware component to create the response.
*
* @param ServerRequestInterface $request
* @param DelegateInterface $delegate
*
* @param RequestHandlerInterface $handler
* @return ResponseInterface
*
*/
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$requestMethod = $request->getMethod();
$key = str_replace(['\\', '/', ':', '*', '?', '"', '<', '>', '|'], '_', $request->getUri()->getPath().'?'.$request->getUri()->getQuery());
Expand All @@ -56,7 +57,7 @@ public function process(ServerRequestInterface $request, DelegateInterface $dele
return $cacheResponse;
} else {
$this->log->debug("Cache MISS on key $key");
$response = $delegate->process($request);
$response = $handler->handle($request);

$noCache = false;
if ($response->hasHeader('Mouf-Cache-Control') && $response->getHeader('Mouf-Cache-Control')[0] == 'no-cache') {
Expand Down
12 changes: 6 additions & 6 deletions src/Mouf/Mvc/Splash/Routers/ExceptionRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Mouf\Mvc\Splash\Routers;

use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Mouf\Mvc\Splash\Controllers\Http500HandlerInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Log\LoggerInterface;
use Mouf\Mvc\Splash\Services\SplashUtils;

Expand Down Expand Up @@ -77,14 +77,14 @@ function () use ($t, $request) {
* to the next middleware component to create the response.
*
* @param Request $request
* @param DelegateInterface $delegate
*
* @return Response
* @param RequestHandlerInterface $handler
* @return ResponseInterface
*/
public function process(Request $request, DelegateInterface $delegate)
public function process(Request $request, RequestHandlerInterface $handler): ResponseInterface
{
try {
return $delegate->process($request);
return $handler->handle($request);
} catch (\Throwable $t) {
return $this->handleException($t, $request);
}
Expand Down
11 changes: 6 additions & 5 deletions src/Mouf/Mvc/Splash/Routers/NotFoundRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

namespace Mouf\Mvc\Splash\Routers;

use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Mouf\Mvc\Splash\Controllers\Http404HandlerInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Log\LoggerInterface;
use Mouf\Mvc\Splash\Services\SplashUtils;

Expand Down Expand Up @@ -41,11 +42,11 @@ public function __construct(Http404HandlerInterface $pageNotFoundController, Log
* to the next middleware component to create the response.
*
* @param Request $request
* @param DelegateInterface $delegate
*
* @return Response
* @param RequestHandlerInterface $handler
* @return ResponseInterface
*/
public function process(Request $request, DelegateInterface $delegate)
public function process(Request $request, RequestHandlerInterface $handler): ResponseInterface
{
if ($this->log) {
$this->log->info('404 - Page not found on URL: '.$request->getUri()->getPath());
Expand Down
43 changes: 8 additions & 35 deletions src/Mouf/Mvc/Splash/Routers/PhpVarsCheckRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

namespace Mouf\Mvc\Splash\Routers;

use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Mouf\Mvc\Splash\Utils\SplashException;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Log\LoggerInterface;

/**
Expand All @@ -19,12 +20,6 @@
*/
class PhpVarsCheckRouter implements MiddlewareInterface
{
/**
* The logger used by Splash.
*
* @var LoggerInterface
*/
private $log;

/**
* A simple counter to check requests' length (GET, POST, REQUEST).
Expand All @@ -33,16 +28,6 @@ class PhpVarsCheckRouter implements MiddlewareInterface
*/
private $count;

/**
* @Important
*
* @param LoggerInterface $log The logger used by Splash
*/
public function __construct(LoggerInterface $log = null)
{
$this->log = $log;
}

/**
* Get the min in 2 values if there exist.
*
Expand Down Expand Up @@ -113,12 +98,12 @@ private function countRecursive($item, $key)
* to the next middleware component to create the response.
*
* @param Request $request
* @param DelegateInterface $delegate
*
* @return Response
* @throws \Mouf\Mvc\Splash\Utils\SplashException
* @param RequestHandlerInterface $handler
* @return ResponseInterface
* @throws SplashException
*/
public function process(Request $request, DelegateInterface $delegate)
public function process(Request $request, RequestHandlerInterface $handler): ResponseInterface
{
// Check if there is a limit of input number in php
// Throw exception if the limit is reached
Expand All @@ -128,9 +113,6 @@ public function process(Request $request, DelegateInterface $delegate)
$this->count = 0;
array_walk_recursive($_GET, array($this, 'countRecursive'));
if ($this->count === $maxGet) {
if ($this->log !== null) {
$this->log->error('Max input vars reaches for get parameters ({maxGet}). Check your variable max_input_vars in php.ini or suhosin module suhosin.get.max_vars.', ['maxGet' => $maxGet]);
}
throw new SplashException('Max input vars reaches for get parameters ('.$maxGet.'). Check your variable max_input_vars in php.ini or suhosin module suhosin.get.max_vars.');
}
}
Expand All @@ -141,9 +123,6 @@ public function process(Request $request, DelegateInterface $delegate)
$this->count = 0;
array_walk_recursive($_POST, array($this, 'countRecursive'));
if ($this->count === $maxPost) {
if ($this->log !== null) {
$this->log->error('Max input vars reaches for post parameters ({maxPost}). Check your variable max_input_vars in php.ini or suhosin module suhosin.post.max_vars.', ['maxPost' => $maxPost]);
}
throw new SplashException('Max input vars reaches for post parameters ('.$maxPost.'). Check your variable max_input_vars in php.ini or suhosin module suhosin.post.max_vars.');
}
}
Expand All @@ -154,19 +133,13 @@ public function process(Request $request, DelegateInterface $delegate)
$this->count = 0;
array_walk_recursive($_REQUEST, array($this, 'countRecursive'));
if ($this->count === $maxRequest) {
if ($this->log !== null) {
$this->log->error('Max input vars reaches for request parameters ({maxRequest}). Check your variable max_input_vars in php.ini or suhosin module suhosin.request.max_vars.', ['maxRequest' => $maxRequest]);
}
throw new SplashException('Max input vars reaches for request parameters ('.$maxRequest.'). Check your variable max_input_vars in php.ini or suhosin module suhosin.request.max_vars.');
}
}
}
if (isset($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'post' && empty($_POST) && empty($_FILES)) {
$maxPostSize = self::iniGetBytes('post_max_size');
if ($_SERVER['CONTENT_LENGTH'] > $maxPostSize) {
if ($this->log !== null) {
$this->log->error('Max post size exceeded! Got {length} bytes, but limit is {maxPostSize} bytes. Edit post_max_size setting in your php.ini.', ['length' => $_SERVER['CONTENT_LENGTH'], 'maxPostSize' => $maxPostSize]);
}
throw new SplashException(
sprintf('Max post size exceeded! Got %s bytes, but limit is %s bytes. Edit post_max_size setting in your php.ini.',
$_SERVER['CONTENT_LENGTH'],
Expand All @@ -177,6 +150,6 @@ public function process(Request $request, DelegateInterface $delegate)
}

//If no Exception has been thrown, call next router
return $delegate->process($request);
return $handler->handle($request);
}
}
12 changes: 6 additions & 6 deletions src/Mouf/Mvc/Splash/Routers/SplashDefaultRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use Cache\Adapter\Void\VoidCachePool;
use Interop\Container\ContainerInterface;
use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Mouf\Mvc\Splash\Controllers\Http400HandlerInterface;
use Mouf\Mvc\Splash\Controllers\Http404HandlerInterface;
use Mouf\Mvc\Splash\Controllers\Http500HandlerInterface;
Expand All @@ -19,6 +17,8 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Mouf\Mvc\Splash\Store\SplashUrlNode;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Log\LoggerInterface;
use Mouf\Mvc\Splash\Services\SplashRequestContext;
use Mouf\Mvc\Splash\Services\SplashUtils;
Expand Down Expand Up @@ -409,17 +409,17 @@ public function purgeUrlsCache()
* to the next middleware component to create the response.
*
* @param ServerRequestInterface $request
* @param DelegateInterface $delegate
*
* @param RequestHandlerInterface $handler
* @return ResponseInterface
*/
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
// create a dummy response to keep compatibility with old middlewares.
$response = new Response();

return $this($request, $response, function($request) use ($delegate) {
return $delegate->process($request);
return $this($request, $response, function($request) use ($handler) {
return $handler->handle($request);
});
}
}