silverstripe-framework/tests/php/Control/DirectorTest/TestMiddleware.php
Damian Mooyman d20ab50f9d API Stronger Injector service unregistration
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()
2017-06-27 13:32:39 +12:00

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;
}
}