mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
d20ab50f9d
BUG Fix up test regressions FIX director references to request object API Move all middlewares to common namespace API Implement RequestHandlerMiddlewareAdapter ENHANCEMENT Improve IP address parsing Fix up PHPDoc / psr2 linting BUG Fix property parsing in TrustedProxyMiddleware BUG Fix Director::is_https()
78 lines
1.9 KiB
PHP
78 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace SilverStripe\Control;
|
|
|
|
use SilverStripe\Control\Middleware\HTTPMiddleware;
|
|
use SilverStripe\Core\Injector\Injectable;
|
|
use SilverStripe\Dev\Deprecation;
|
|
|
|
/**
|
|
* Middleware that provides back-support for the deprecated RequestFilter API.
|
|
*
|
|
* @deprecated 4.0..5.0 Use HTTPMiddleware directly instead.
|
|
*/
|
|
class RequestProcessor implements HTTPMiddleware
|
|
{
|
|
use Injectable;
|
|
|
|
/**
|
|
* List of currently assigned request filters
|
|
*
|
|
* @var RequestFilter[]
|
|
*/
|
|
private $filters = array();
|
|
|
|
/**
|
|
* Construct new RequestFilter with a list of filter objects
|
|
*
|
|
* @param RequestFilter[] $filters
|
|
*/
|
|
public function __construct($filters = array())
|
|
{
|
|
$this->filters = $filters;
|
|
}
|
|
|
|
/**
|
|
* Assign a list of request filters
|
|
*
|
|
* @param RequestFilter[] $filters
|
|
* @return $this
|
|
*/
|
|
public function setFilters($filters)
|
|
{
|
|
$this->filters = $filters;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public function process(HTTPRequest $request, callable $delegate)
|
|
{
|
|
if ($this->filters) {
|
|
Deprecation::notice(
|
|
'5.0',
|
|
'Deprecated RequestFilters are in use. Apply HTTPMiddleware to Director.middlewares instead.'
|
|
);
|
|
}
|
|
|
|
foreach ($this->filters as $filter) {
|
|
$res = $filter->preRequest($request);
|
|
if ($res === false) {
|
|
return new HTTPResponse(_t(__CLASS__.'.INVALID_REQUEST', 'Invalid request'), 400);
|
|
}
|
|
}
|
|
|
|
$response = $delegate($request);
|
|
|
|
foreach ($this->filters as $filter) {
|
|
$res = $filter->postRequest($request, $response);
|
|
if ($res === false) {
|
|
return new HTTPResponse(_t(__CLASS__ . '.REQUEST_ABORTED', 'Request aborted'), 500);
|
|
}
|
|
}
|
|
|
|
return $response;
|
|
}
|
|
}
|