BigPipeTestSubscriber.php 2.87 KB
 effulgentsia committed Mar 01, 2016 1 2 3 4 5 6 7 8 9 getResponse(); if (!$response instanceof AttachmentsInterface) { return; }$attachments = $response->getAttachments(); if (!isset($attachments['big_pipe_placeholders']) && !isset($attachments['big_pipe_nojs_placeholders'])) { if (strpos($response->getContent(), static::CONTENT_TRIGGER_EXCEPTION) !== FALSE) { throw new \Exception('Oh noes!'); } } }  effulgentsia committed Mar 01, 2016 50 51 52 53 54 55  /** * Exposes all BigPipe placeholders (JS and no-JS) via headers for testing. * * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event * The event to process. */  catch committed Mar 30, 2016 56  public function onRespondSetBigPipeDebugPlaceholderHeaders(FilterResponseEvent$event) {  effulgentsia committed Mar 01, 2016 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79  $response =$event->getResponse(); if (!$response instanceof HtmlResponse) { return; }$attachments = $response->getAttachments();$response->headers->set('BigPipe-Test-Placeholders', ''); $response->headers->set('BigPipe-Test-No-Js-Placeholders', ''); if (!empty($attachments['big_pipe_placeholders'])) { $response->headers->set('BigPipe-Test-Placeholders', implode(' ', array_keys($attachments['big_pipe_placeholders']))); } if (!empty($attachments['big_pipe_nojs_placeholders'])) {$response->headers->set('BigPipe-Test-No-Js-Placeholders', implode(' ', array_map('rawurlencode', array_keys($attachments['big_pipe_nojs_placeholders'])))); } } /** * {@inheritdoc} */ public static function getSubscribedEvents() {  catch committed Mar 30, 2016 80 81 82 83 84  // Run just before \Drupal\big_pipe\EventSubscriber\HtmlResponseBigPipeSubscriber::onRespond().$events[KernelEvents::RESPONSE][] = ['onRespondSetBigPipeDebugPlaceholderHeaders', -9999]; // Run just after \Drupal\big_pipe\EventSubscriber\HtmlResponseBigPipeSubscriber::onRespond(). $events[KernelEvents::RESPONSE][] = ['onRespondTriggerException', -10001];  effulgentsia committed Mar 01, 2016 85 86 87 88 89  return$events; } }