Commit b99d11fa authored by katbailey's avatar katbailey Committed by Crell
Browse files

Adding a ResponseSubscriber for taking care of end of request tasks, including...

Adding a ResponseSubscriber for taking care of end of request tasks, including caching of pages and system paths
parent 71146f23
......@@ -5242,7 +5242,7 @@ function _drupal_bootstrap_full() {
*
* @see drupal_page_header()
*/
function drupal_page_set_cache() {
function drupal_page_set_cache($response_body) {
global $base_root;
if (drupal_page_is_cacheable()) {
......@@ -5250,7 +5250,7 @@ function drupal_page_set_cache() {
'cid' => $base_root . request_uri(),
'data' => array(
'path' => $_GET['q'],
'body' => ob_get_clean(),
'body' => $response_body,
'title' => drupal_get_title(),
'headers' => array(),
),
......
......@@ -24,6 +24,7 @@
use Drupal\Core\EventSubscriber\PathSubscriber;
use Drupal\Core\EventSubscriber\LegacyControllerSubscriber;
use Drupal\Core\EventSubscriber\MaintenanceModeSubscriber;
use Drupal\Core\EventSubscriber\ResponseSubscriber;
use Exception;
......@@ -74,6 +75,7 @@ public function __construct(EventDispatcherInterface $dispatcher, ControllerReso
$this->dispatcher->addSubscriber(new MaintenanceModeSubscriber());
$this->dispatcher->addSubscriber(new PathSubscriber());
$this->dispatcher->addSubscriber(new LegacyControllerSubscriber());
$this->dispatcher->addSubscriber(new ResponseSubscriber());
// Some other form of error occured that wasn't handled by another kernel
// listener. That could mean that it's a method/mime-type/error
......
<?php
namespace Drupal\Core\EventSubscriber;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* @file
*
* Definition of Drupal\Core\EventSubscriber\ResponseSubscriber;
*/
/**
* Subscriber for all responses.
*/
class ResponseSubscriber implements EventSubscriberInterface {
/**
* Performs end of request tasks.
*
* @todo The body of this function has just been copied almost verbatim from
* drupal_page_footer(), with the exception of now passing the response
* content to drupal_page_set_cache(). There's probably a lot in here that
* needs to get removed/changed.
*
* @param FilterResponseEvent $event
* The Event to process.
*/
public function onKernelResponse(FilterResponseEvent $event) {
global $user;
module_invoke_all('exit');
// Commit the user session, if needed.
drupal_session_commit();
$response = $event->getResponse();
$config = config('system.performance');
if ($config->get('cache') && ($cache = drupal_page_set_cache($response->getContent()))) {
drupal_serve_page_from_cache($cache);
}
else {
ob_flush();
}
_registry_check_code(REGISTRY_WRITE_LOOKUP_CACHE);
drupal_cache_system_paths();
module_implements_write_cache();
system_run_automated_cron();
}
/**
* Registers the methods in this class that should be listeners.
*
* @return array
* An array of event listener definitions.
*/
static function getSubscribedEvents() {
$events[KernelEvents::RESPONSE][] = array('onKernelResponse');
return $events;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment