<?php
declare(strict_types=1);
namespace Bluue\TicketsBundle\EventSubscriber;
use ReflectionClass;
use App\Services\CheckBundleInstall;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ConfigureStatisticsMenuConfigurationSubscriber implements EventSubscriberInterface
{
/**
* @var TranslatorInterface
*/
private TranslatorInterface $tr;
/**
* @var Security
*/
private Security $security;
/**
* @param TranslatorInterface $tr
* @param Security $security
*/
public function __construct(
TranslatorInterface $tr,
Security $security
) {
$this->tr = $tr;
$this->security = $security;
}
/**
* @return array
*/
public static function getSubscribedEvents(): array
{
if (CheckBundleInstall::exist('tickets-bundle')) {
$reflectionClass = new ReflectionClass('Bluue\StatisticsBundle\Event\MenuStatisticPageEvent');
return [
$reflectionClass->getConstant('NAME') => 'onLoad'
];
}
return [];
}
/**
* @param object $event
* @return void
*/
public function onLoad(object $event): void
{
if (!$this->security->isGranted('ROLE__TICKETS__READ_ONLY')) {
return;
}
$pages = $event->getPages();
$pages[] = [
'id' => 'tickets_bundle__statistics',
'name' => $this->tr->trans('Tickets', [], 'TicketsBundle')
];
$event->setPages($pages);
}
}