mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
NEW: Replace FlushRequestFilter with FlushMiddleware
This commit is contained in:
parent
95a266c6b9
commit
e855622890
@ -261,7 +261,7 @@ mappings:
|
|||||||
Cookie_Backend: SilverStripe\Control\Cookie_Backend
|
Cookie_Backend: SilverStripe\Control\Cookie_Backend
|
||||||
CookieJar: SilverStripe\Control\CookieJar
|
CookieJar: SilverStripe\Control\CookieJar
|
||||||
Director: SilverStripe\Control\Director
|
Director: SilverStripe\Control\Director
|
||||||
FlushRequestFilter: SilverStripe\Control\FlushRequestFilter
|
FlushRequestFilter: SilverStripe\Control\FlushMiddleware
|
||||||
HTTP: SilverStripe\Control\HTTP
|
HTTP: SilverStripe\Control\HTTP
|
||||||
SS_HTTPRequest: SilverStripe\Control\HTTPRequest
|
SS_HTTPRequest: SilverStripe\Control\HTTPRequest
|
||||||
SS_HTTPResponse: SilverStripe\Control\HTTPResponse
|
SS_HTTPResponse: SilverStripe\Control\HTTPResponse
|
||||||
@ -496,8 +496,8 @@ mappings:
|
|||||||
TestRequestFilter: SilverStripe\Control\Tests\DirectorTest\TestRequestFilter
|
TestRequestFilter: SilverStripe\Control\Tests\DirectorTest\TestRequestFilter
|
||||||
DirectorTestRequest_Controller: SilverStripe\Control\Tests\DirectorTest\TestController
|
DirectorTestRequest_Controller: SilverStripe\Control\Tests\DirectorTest\TestController
|
||||||
FakeController: SilverStripe\Control\Tests\FakeController
|
FakeController: SilverStripe\Control\Tests\FakeController
|
||||||
FlushRequestFilterTest: SilverStripe\Control\Tests\FlushRequestFilterTest
|
FlushRequestFilterTest: SilverStripe\Control\Tests\FlushMiddlewareTest
|
||||||
FlushRequestFilterTest_Flushable: SilverStripe\Control\Tests\FlushRequestFilterTest\TestFlushable
|
FlushRequestFilterTest_Flushable: SilverStripe\Control\Tests\FlushMiddlewareTest\TestFlushable
|
||||||
HTTPRequestTest: SilverStripe\Control\Tests\HTTPRequestTest
|
HTTPRequestTest: SilverStripe\Control\Tests\HTTPRequestTest
|
||||||
HTTPResponseTest: SilverStripe\Control\Tests\HTTPResponseTest
|
HTTPResponseTest: SilverStripe\Control\Tests\HTTPResponseTest
|
||||||
HTTPTest: SilverStripe\Control\Tests\HTTPTest
|
HTTPTest: SilverStripe\Control\Tests\HTTPTest
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
---
|
---
|
||||||
Name: requestprocessors
|
Name: requestprocessors
|
||||||
---
|
---
|
||||||
SilverStripe\Core\Injector\Injector:
|
SilverStripe\Control\Director:
|
||||||
FlushRequestFilter:
|
middlewares:
|
||||||
class: SilverStripe\Control\FlushRequestFilter
|
RequestProcessor: 'SilverStripe\Control\RequestProcessor'
|
||||||
SilverStripe\Control\RequestProcessor:
|
FlushMiddleware: '%$SilverStripe\Control\FlushMiddleware'
|
||||||
properties:
|
|
||||||
filters:
|
|
||||||
- '%$FlushRequestFilter'
|
|
||||||
|
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
Name: rootroutes
|
Name: rootroutes
|
||||||
---
|
---
|
||||||
SilverStripe\Control\Director:
|
SilverStripe\Control\Director:
|
||||||
middlewares:
|
|
||||||
RequestProcessor: 'SilverStripe\Control\RequestProcessor'
|
|
||||||
rules:
|
rules:
|
||||||
'': SilverStripe\Control\Controller
|
'': SilverStripe\Control\Controller
|
||||||
---
|
---
|
||||||
|
@ -6,7 +6,7 @@ summary: Allows a class to define it's own flush functionality.
|
|||||||
## Introduction
|
## Introduction
|
||||||
|
|
||||||
Allows a class to define it's own flush functionality, which is triggered when `flush=1` is requested in the URL.
|
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].
|
implementors of [api:Flushable].
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
@ -8,20 +8,19 @@ use SilverStripe\Core\ClassInfo;
|
|||||||
/**
|
/**
|
||||||
* Triggers a call to flush() on all implementors of Flushable.
|
* 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())) {
|
if (array_key_exists('flush', $request->getVars())) {
|
||||||
foreach (ClassInfo::implementorsOf(Flushable::class) as $class) {
|
foreach (ClassInfo::implementorsOf(Flushable::class) as $class) {
|
||||||
$class::flush();
|
$class::flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function postRequest(HTTPRequest $request, HTTPResponse $response)
|
return $delegate($request);
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -14,7 +14,7 @@ interface Flushable
|
|||||||
* parameter has been set. Each class that implements Flushable implements
|
* parameter has been set. Each class that implements Flushable implements
|
||||||
* this function which looks after it's own specific flushing functionality.
|
* this function which looks after it's own specific flushing functionality.
|
||||||
*
|
*
|
||||||
* @see FlushRequestFilter
|
* @see FlushMiddleware
|
||||||
*/
|
*/
|
||||||
public static function flush();
|
public static function flush();
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
namespace SilverStripe\Control\Tests;
|
namespace SilverStripe\Control\Tests;
|
||||||
|
|
||||||
use SilverStripe\Control\Tests\FlushRequestFilterTest\TestFlushable;
|
use SilverStripe\Control\Tests\FlushMiddlewareTest\TestFlushable;
|
||||||
use SilverStripe\Dev\FunctionalTest;
|
use SilverStripe\Dev\FunctionalTest;
|
||||||
|
|
||||||
class FlushRequestFilterTest extends FunctionalTest
|
class FlushMiddlewareTest extends FunctionalTest
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Assert that classes that implement flushable are called
|
* Assert that classes that implement flushable are called
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace SilverStripe\Control\Tests\FlushRequestFilterTest;
|
namespace SilverStripe\Control\Tests\FlushMiddlewareTest;
|
||||||
|
|
||||||
use SilverStripe\Core\Flushable;
|
use SilverStripe\Core\Flushable;
|
||||||
use SilverStripe\Dev\TestOnly;
|
use SilverStripe\Dev\TestOnly;
|
Loading…
Reference in New Issue
Block a user