Skip to content
Permalink
Browse files

NEW: Replace FlushRequestFilter with FlushMiddleware

  • Loading branch information
sminnee authored and Damian Mooyman committed Jun 23, 2017
1 parent 95a266c commit e85562289045cdc7c5c0c619811444e4b1f4dcd9
@@ -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
@@ -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'

@@ -2,8 +2,6 @@
Name: rootroutes
---
SilverStripe\Control\Director:
middlewares:
RequestProcessor: 'SilverStripe\Control\RequestProcessor'
rules:
'': SilverStripe\Control\Controller
---
@@ -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
@@ -8,20 +8,19 @@
/**
* 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);
}
}
@@ -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();
}
@@ -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
@@ -1,6 +1,6 @@
<?php
namespace SilverStripe\Control\Tests\FlushRequestFilterTest;
namespace SilverStripe\Control\Tests\FlushMiddlewareTest;
use SilverStripe\Core\Flushable;
use SilverStripe\Dev\TestOnly;

0 comments on commit e855622

Please sign in to comment.
You can’t perform that action at this time.