You are here

public function EventSubscriber::onRequest in JS Callback Handler 8.3

Same name in this branch
  1. 8.3 src/EventSubscriber.php \Drupal\js\EventSubscriber::onRequest()
  2. 8.3 js_callback_examples/src/EventSubscriber.php \Drupal\js_callback_examples\EventSubscriber::onRequest()

Parameters

\Symfony\Component\HttpKernel\Event\GetResponseEvent $event:

File

src/EventSubscriber.php, line 77

Class

EventSubscriber
RouteSubscriber.

Namespace

Drupal\js

Code

public function onRequest(GetResponseEvent $event) {
  $request = $event
    ->getRequest();
  if ($this->js
    ->isExecuting($request)) {

    // Immediately start capturing any output.
    ob_start();

    // Override error and exception handlers to capture output.
    if (!$this->js
      ->silencePhpErrors()) {
      set_error_handler([
        $this->js,
        'errorHandler',
      ]);
      set_exception_handler([
        $this->js,
        'exceptionHandler',
      ]);
      register_shutdown_function([
        $this->js,
        'fatalErrorHandler',
      ]);
    }
  }
}