2014-08-16 12:51:17 +12:00
|
|
|
<?php
|
2016-06-15 16:03:16 +12:00
|
|
|
|
2016-08-19 10:51:35 +12:00
|
|
|
namespace SilverStripe\Control;
|
|
|
|
|
2017-01-26 17:20:08 +13:00
|
|
|
use SilverStripe\Core\Flushable;
|
2016-08-19 10:51:35 +12:00
|
|
|
use SilverStripe\Core\ClassInfo;
|
|
|
|
|
2014-08-16 12:51:17 +12:00
|
|
|
/**
|
|
|
|
* Triggers a call to flush() on all implementors of Flushable.
|
|
|
|
*/
|
2017-06-23 12:29:11 +12:00
|
|
|
class FlushMiddleware implements HTTPMiddleware
|
2016-11-29 12:31:16 +13:00
|
|
|
{
|
2017-06-23 12:29:11 +12:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
public function process(HTTPRequest $request, callable $delegate)
|
2016-11-29 12:31:16 +13:00
|
|
|
{
|
|
|
|
if (array_key_exists('flush', $request->getVars())) {
|
2017-01-26 17:20:08 +13:00
|
|
|
foreach (ClassInfo::implementorsOf(Flushable::class) as $class) {
|
2016-11-29 12:31:16 +13:00
|
|
|
$class::flush();
|
|
|
|
}
|
|
|
|
}
|
2014-08-16 12:51:17 +12:00
|
|
|
|
2017-06-23 12:29:11 +12:00
|
|
|
return $delegate($request);
|
2016-11-29 12:31:16 +13:00
|
|
|
}
|
2014-08-16 12:51:17 +12:00
|
|
|
}
|