mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-06 01:31:22 +02:00
41 lines
881 B
PHP
41 lines
881 B
PHP
|
<?php
|
||
|
|
||
|
namespace SilverStripe\Control\Tests\DirectorTest;
|
||
|
|
||
|
use SilverStripe\Control\HTTPRequest;
|
||
|
use SilverStripe\Control\HTTPResponse;
|
||
|
use SilverStripe\Control\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;
|
||
|
}
|
||
|
}
|