2014-08-16 02:51:17 +02:00
|
|
|
<?php
|
2016-06-15 06:03:16 +02:00
|
|
|
|
2017-06-25 05:12:29 +02:00
|
|
|
namespace SilverStripe\Control\Middleware;
|
2016-08-19 00:51:35 +02:00
|
|
|
|
2019-02-27 02:50:49 +01:00
|
|
|
use SilverStripe\Control\Director;
|
2017-06-25 05:12:29 +02:00
|
|
|
use SilverStripe\Control\HTTPRequest;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Core\ClassInfo;
|
2017-06-25 05:12:29 +02:00
|
|
|
use SilverStripe\Core\Flushable;
|
2016-08-19 00:51:35 +02:00
|
|
|
|
2014-08-16 02:51:17 +02:00
|
|
|
/**
|
|
|
|
* Triggers a call to flush() on all implementors of Flushable.
|
|
|
|
*/
|
2017-06-23 02:29:11 +02:00
|
|
|
class FlushMiddleware implements HTTPMiddleware
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-06-23 02:29:11 +02:00
|
|
|
public function process(HTTPRequest $request, callable $delegate)
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2019-02-27 02:50:49 +01:00
|
|
|
if (Director::isManifestFlushed()) {
|
2018-06-12 07:52:31 +02:00
|
|
|
// Disable cache when flushing
|
|
|
|
HTTPCacheControlMiddleware::singleton()->disableCache(true);
|
|
|
|
|
2017-01-26 05:20:08 +01:00
|
|
|
foreach (ClassInfo::implementorsOf(Flushable::class) as $class) {
|
2017-06-25 05:12:29 +02:00
|
|
|
/** @var Flushable|string $class */
|
2016-11-29 00:31:16 +01:00
|
|
|
$class::flush();
|
|
|
|
}
|
|
|
|
}
|
2014-08-16 02:51:17 +02:00
|
|
|
|
2017-06-23 02:29:11 +02:00
|
|
|
return $delegate($request);
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
2014-08-16 02:51:17 +02:00
|
|
|
}
|