title: ZF2 - Make onbootstrap events in one module supersede every other module
body: <p>I have a ZF2 module called "Browsercheck", when used with other modules, checks the user's browser and shows an "Unsupported Browser" page if the browser is not supported. The issue I am having is, that the following code which is onBootstrap of the "Browsercheck" is not taking the first preference when other modules encounter an exception or a 404 error. IT works otherwise.</p>
  
  <p>How can I make sure this code executes for every event and supersede any other event? Ideally in ZF1, I use code like this in index.php.. but not sure how it should be in ZF2. Basically if the browser is not supported, it shouldn't matter whether it's a 404 or an exception. It should go ahead and render the unsupported browser page.</p>
  
  <pre><code>public function onBootstrap(MvcEvent $e)
  {   
      $sharedEvents = $e-&gt;getApplication()-&gt;getEventManager()-&gt;getSharedManager();
      $sharedEvents-&gt;attach('Zend\Mvc\Controller\AbstractController','dispatch',
      function($event)
      {
          $browser = new \BrowserCheck\Service\BrowserCheck();
          if (!$browser-&gt;isCompatible())
          {
              $viewModel = new \Zend\View\Model\ViewModel();
              $viewModel-&gt;setTerminal(true);
  
              $request = $event-&gt;getRequest();
              $response = $event-&gt;getResponse();
  
  
              $viewModel-&gt;setTemplate('browser-check/index/index.phtml');
              //Replace the entire view
              $event-&gt;setViewModel($viewModel);
              $event-&gt;stopPropagation();
              $response-&gt;setStatusCode(200);
              return $viewModel;
          }
      });
  }
  </code></pre>
  
  <p><strong>UPDATE:</strong></p>
  
  <pre><code>$browserEventListener = function($event)
      {
          $browser = new \BrowserCheck\Service\BrowserCheck();
          if (!$browser-&gt;isCompatible())
          {
              $viewModel = new \Zend\View\Model\ViewModel();
              $viewModel-&gt;setTerminal(true);
  
              $request = $event-&gt;getRequest();
              $response = $event-&gt;getResponse();
  
              $viewModel-&gt;setTemplate('browser-check/index/index.phtml');
  
              //Replace the entire view
              $event-&gt;setViewModel($viewModel);
              $event-&gt;stopPropagation();
              $response-&gt;setStatusCode(200);
              return $viewModel;
          }
      };
  $sharedEvents = $e-&gt;getApplication()-&gt;getEventManager()-&gt;getSharedManager();
  $sharedEvents-&gt;attach('Zend\Mvc\Controller\AbstractController',
    array('dispatch','dispatch.error'), $browserEventListener, 100);
  </code></pre>