NEW: Replace FlushRequestFilter with FlushMiddleware

This commit is contained in:
Sam Minnee 2017-06-23 12:29:11 +12:00 committed by Damian Mooyman
parent 95a266c6b9
commit e855622890
8 changed files with 18 additions and 24 deletions

View File

@ -261,7 +261,7 @@ mappings:
Cookie_Backend: SilverStripe\Control\Cookie_Backend
CookieJar: SilverStripe\Control\CookieJar
Director: SilverStripe\Control\Director
FlushRequestFilter: SilverStripe\Control\FlushRequestFilter
FlushRequestFilter: SilverStripe\Control\FlushMiddleware
HTTP: SilverStripe\Control\HTTP
SS_HTTPRequest: SilverStripe\Control\HTTPRequest
SS_HTTPResponse: SilverStripe\Control\HTTPResponse
@ -496,8 +496,8 @@ mappings:
TestRequestFilter: SilverStripe\Control\Tests\DirectorTest\TestRequestFilter
DirectorTestRequest_Controller: SilverStripe\Control\Tests\DirectorTest\TestController
FakeController: SilverStripe\Control\Tests\FakeController
FlushRequestFilterTest: SilverStripe\Control\Tests\FlushRequestFilterTest
FlushRequestFilterTest_Flushable: SilverStripe\Control\Tests\FlushRequestFilterTest\TestFlushable
FlushRequestFilterTest: SilverStripe\Control\Tests\FlushMiddlewareTest
FlushRequestFilterTest_Flushable: SilverStripe\Control\Tests\FlushMiddlewareTest\TestFlushable
HTTPRequestTest: SilverStripe\Control\Tests\HTTPRequestTest
HTTPResponseTest: SilverStripe\Control\Tests\HTTPResponseTest
HTTPTest: SilverStripe\Control\Tests\HTTPTest

View File

@ -1,11 +1,8 @@
---
Name: requestprocessors
---
SilverStripe\Core\Injector\Injector:
FlushRequestFilter:
class: SilverStripe\Control\FlushRequestFilter
SilverStripe\Control\RequestProcessor:
properties:
filters:
- '%$FlushRequestFilter'
SilverStripe\Control\Director:
middlewares:
RequestProcessor: 'SilverStripe\Control\RequestProcessor'
FlushMiddleware: '%$SilverStripe\Control\FlushMiddleware'

View File

@ -2,8 +2,6 @@
Name: rootroutes
---
SilverStripe\Control\Director:
middlewares:
RequestProcessor: 'SilverStripe\Control\RequestProcessor'
rules:
'': SilverStripe\Control\Controller
---

View File

@ -6,7 +6,7 @@ summary: Allows a class to define it's own flush functionality.
## Introduction
Allows a class to define it's own flush functionality, which is triggered when `flush=1` is requested in the URL.
[api:FlushRequestFilter] is run before a request is made, calling `flush()` statically on all
[api:FlushMiddleware] is run before a request is made, calling `flush()` statically on all
implementors of [api:Flushable].
## Usage

View File

@ -8,20 +8,19 @@ use SilverStripe\Core\ClassInfo;
/**
* Triggers a call to flush() on all implementors of Flushable.
*/
class FlushRequestFilter implements RequestFilter
class FlushMiddleware implements HTTPMiddleware
{
public function preRequest(HTTPRequest $request)
/**
* @inheritdoc
*/
public function process(HTTPRequest $request, callable $delegate)
{
if (array_key_exists('flush', $request->getVars())) {
foreach (ClassInfo::implementorsOf(Flushable::class) as $class) {
$class::flush();
}
}
return true;
}
public function postRequest(HTTPRequest $request, HTTPResponse $response)
{
return true;
return $delegate($request);
}
}

View File

@ -14,7 +14,7 @@ interface Flushable
* parameter has been set. Each class that implements Flushable implements
* this function which looks after it's own specific flushing functionality.
*
* @see FlushRequestFilter
* @see FlushMiddleware
*/
public static function flush();
}

View File

@ -2,10 +2,10 @@
namespace SilverStripe\Control\Tests;
use SilverStripe\Control\Tests\FlushRequestFilterTest\TestFlushable;
use SilverStripe\Control\Tests\FlushMiddlewareTest\TestFlushable;
use SilverStripe\Dev\FunctionalTest;
class FlushRequestFilterTest extends FunctionalTest
class FlushMiddlewareTest extends FunctionalTest
{
/**
* Assert that classes that implement flushable are called

View File

@ -1,6 +1,6 @@
<?php
namespace SilverStripe\Control\Tests\FlushRequestFilterTest;
namespace SilverStripe\Control\Tests\FlushMiddlewareTest;
use SilverStripe\Core\Flushable;
use SilverStripe\Dev\TestOnly;