wpsy/EventSubscriber/BeforeActionSubscriber.php line 25

Open in your IDE?
  1. <?php
  2. namespace Metabolism\WordpressBundle\EventSubscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  5. use Symfony\Component\HttpKernel\KernelEvents;
  6. class BeforeActionSubscriber implements EventSubscriberInterface
  7. {
  8.     /**
  9.      * @return array
  10.      */
  11.     public static function getSubscribedEvents()
  12.     {
  13.         return [KernelEvents::CONTROLLER => 'onKernelController'];
  14.     }
  15.     /**
  16.      * @param ControllerEvent $event
  17.      * @return void
  18.      * @throws \Exception
  19.      */
  20.     public function onKernelController(ControllerEvent $event)
  21.     {
  22.         if ( (method_exists($event'isMainRequest') && !$event->isMainRequest()) )
  23.             return;
  24.         if( wp_is_maintenance_mode() || (function_exists('wp_maintenance_mode') && wp_maintenance_mode()) )
  25.             throw new \Exception('Service Unavailable'503);
  26.     }
  27. }