<?php declare(strict_types=1);
namespace TigerMedia\Base\Subscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use TigerMedia\Base\Service\UtilitiesService;
use function clearstatcache;
use function opcache_get_status;
use function opcache_reset;
use function phpinfo;
use function print_r;
class EnableDeveloperTools implements EventSubscriberInterface
{
private UtilitiesService $utilitiesService;
public function __construct(UtilitiesService $utilitiesService)
{
$this->utilitiesService = $utilitiesService;
}
public static function getSubscribedEvents(): array
{
return [
KernelEvents::REQUEST => 'onKernelRequest'
];
}
public function onKernelRequest(RequestEvent $event): void
{
if (!$this->utilitiesService->isTigerOffice()) {
return;
}
$shortcuts = [
'phpinfo' => function () {
echo '</pre>';
phpinfo();
},
'opcache' => function() {
print_r(opcache_get_status(false));
},
'reset_opcache' => function() {
echo 'Resetting opcache.. ';
opcache_reset();
echo 'Done';
},
'clearstatcache' => function() {
echo 'Clearing file status cache.. ';
clearstatcache();
echo 'Done';
},
];
foreach ($shortcuts as $shortcut => $callable) {
if ($event->getRequest()->query->has($shortcut)) {
echo '<pre>';
$callable();
echo '</pre>';
}
}
}
}