diff --git a/core/modules/locale/tests/modules/locale_test/lib/Drupal/locale_test/LocaleTestBundle.php b/core/modules/locale/tests/modules/locale_test/lib/Drupal/locale_test/LocaleTestBundle.php index 2f9db4a..c1035ec 100644 --- a/core/modules/locale/tests/modules/locale_test/lib/Drupal/locale_test/LocaleTestBundle.php +++ b/core/modules/locale/tests/modules/locale_test/lib/Drupal/locale_test/LocaleTestBundle.php @@ -14,7 +14,6 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; -use Symfony\Component\DependencyInjection\Reference; /** * Locale Test dependency injection container. @@ -26,9 +25,7 @@ class LocaleTestBundle extends Bundle { */ public function build(ContainerBuilder $container) { // Register our response subscriber to handle finished responses. - $container->register('finish_response_subscriber', 'Drupal\locale_test\LocaleTestFinishResponseSubscriber') - ->addArgument(new Reference('language_manager')) - ->setScope('request') + $container->register('locale_test_finish_response_subscriber', 'Drupal\locale_test\LocaleTestFinishResponseSubscriber') ->addTag('event_subscriber'); } } diff --git a/core/modules/locale/tests/modules/locale_test/lib/Drupal/locale_test/LocaleTestFinishResponseSubscriber.php b/core/modules/locale/tests/modules/locale_test/lib/Drupal/locale_test/LocaleTestFinishResponseSubscriber.php index e62705e..d93ac89 100644 --- a/core/modules/locale/tests/modules/locale_test/lib/Drupal/locale_test/LocaleTestFinishResponseSubscriber.php +++ b/core/modules/locale/tests/modules/locale_test/lib/Drupal/locale_test/LocaleTestFinishResponseSubscriber.php @@ -8,34 +8,51 @@ * override the already configured 'Last-Modified' HTTP header which is set and * needed when a remote translation file is served via a menu callback. So this * is a new event subscriber which saves the value and sets it back. + * It does so with the saveLastModified() method which has a very high priority, + * so it can save the defined header really early in a class property. Then + * later on the setLastModified() method can set the header again using the + * value from this property, since it has a very low priority, it can manipulate + * the header after FinishResponseSubscriber has done its changes. */ namespace Drupal\locale_test; -use Drupal\Core\EventSubscriber\FinishResponseSubscriber; -use Drupal\Core\Language\LanguageManager; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; -use Symfony\Component\HttpKernel\HttpKernelInterface; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Response subscriber to handle finished responses. */ -class LocaleTestFinishResponseSubscriber extends FinishResponseSubscriber { +class LocaleTestFinishResponseSubscriber implements EventSubscriberInterface { + + public $lastModified; + + /** + * Registers the methods in this class that should be listeners. + * + * @return array + * An array of event listener definitions. + */ + public static function getSubscribedEvents() { + $events[KernelEvents::RESPONSE][] = array('saveLastModified', 100); + $events[KernelEvents::RESPONSE][] = array('setLastModified', -100); + return $events; + } + + /** + * Saves the 'Last-Modified' HTTP header in a class property. + */ + public function saveLastModified(FilterResponseEvent $event) { + $this->lastModified = $event->getResponse()->headers->get('Last-Modified'); + } /** - * Overrides Drupal\Core\EventSubscriber\FinishResponseSubscriber:onRespond(). + * Sets the 'Last-Modified' HTTP header to the response. */ - public function onRespond(FilterResponseEvent $event) { - // Save the 'Last-Modified' HTTP header's value. - $response = $event->getResponse(); - $last_modified = $response->headers->get('Last-Modified'); - // Parent method will change it to REQUEST_TIME. - parent::onRespond($event); - if (!empty($last_modified)) { - // But here it's the desired one again. - $response->headers->set('Last-Modified', $last_modified); + public function setLastModified(FilterResponseEvent $event) { + if (!empty($this->lastModified)) { + $event->getResponse()->headers->set('Last-Modified', $this->lastModified); } } }