mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-05 17:21:16 +02:00
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()
41 lines
892 B
PHP
41 lines
892 B
PHP
<?php
|
|
|
|
namespace SilverStripe\Control\Tests\DirectorTest;
|
|
|
|
use SilverStripe\Control\HTTPRequest;
|
|
use SilverStripe\Control\HTTPResponse;
|
|
use SilverStripe\Control\Middleware\HTTPMiddleware;
|
|
use SilverStripe\Dev\TestOnly;
|
|
|
|
class TestMiddleware implements HTTPMiddleware, TestOnly
|
|
{
|
|
public $preCalls = 0;
|
|
public $postCalls = 0;
|
|
|
|
public $failPre = false;
|
|
public $failPost = false;
|
|
|
|
public function process(HTTPRequest $request, callable $delegate)
|
|
{
|
|
$this->preCalls++;
|
|
if ($this->failPre) {
|
|
return new HTTPResponse('Fail pre', 400);
|
|
}
|
|
|
|
$response = $delegate($request);
|
|
|
|
$this->postCalls++;
|
|
if ($this->failPost) {
|
|
return new HTTPResponse('Fail post', 500);
|
|
}
|
|
|
|
return $response;
|
|
}
|
|
|
|
public function reset()
|
|
{
|
|
$this->preCalls = 0;
|
|
$this->postCalls = 0;
|
|
}
|
|
}
|