custom/plugins/TigerBase/src/Subscriber/EnableDeveloperTools.php line 31

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace TigerMedia\Base\Subscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpKernel\Event\RequestEvent;
  5. use Symfony\Component\HttpKernel\KernelEvents;
  6. use TigerMedia\Base\Service\UtilitiesService;
  7. use function clearstatcache;
  8. use function opcache_get_status;
  9. use function opcache_reset;
  10. use function phpinfo;
  11. use function print_r;
  12. class EnableDeveloperTools implements EventSubscriberInterface
  13. {
  14.     private UtilitiesService $utilitiesService;
  15.     public function __construct(UtilitiesService $utilitiesService)
  16.     {
  17.         $this->utilitiesService $utilitiesService;
  18.     }
  19.     public static function getSubscribedEvents(): array
  20.     {
  21.         return [
  22.             KernelEvents::REQUEST => 'onKernelRequest'
  23.         ];
  24.     }
  25.     public function onKernelRequest(RequestEvent $event): void
  26.     {
  27.         if (!$this->utilitiesService->isTigerOffice()) {
  28.             return;
  29.         }
  30.         $shortcuts = [
  31.             'phpinfo' => function () {
  32.                 echo '</pre>';
  33.                 phpinfo();
  34.             },
  35.             'opcache' => function() {
  36.                 print_r(opcache_get_status(false));
  37.             },
  38.             'reset_opcache' => function() {
  39.                 echo 'Resetting opcache.. ';
  40.                 opcache_reset();
  41.                 echo 'Done';
  42.             },
  43.             'clearstatcache' => function() {
  44.                 echo 'Clearing file status cache.. ';
  45.                 clearstatcache();
  46.                 echo 'Done';
  47.             },
  48.         ];
  49.         foreach ($shortcuts as $shortcut => $callable) {
  50.             if ($event->getRequest()->query->has($shortcut)) {
  51.                 echo '<pre>';
  52.                 $callable();
  53.                 echo '</pre>';
  54.             }
  55.         }
  56.     }
  57. }