vendor/bluue/projects-bundle/src/EventSubscriber/ConfigureStatisticsMenuConfigurationSubscriber.php line 55

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Bluue\ProjectsBundle\EventSubscriber;
  4. use ReflectionClass;
  5. use App\Services\CheckBundleInstall;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\Security\Core\Security;
  8. use Symfony\Contracts\Translation\TranslatorInterface;
  9. class ConfigureStatisticsMenuConfigurationSubscriber implements EventSubscriberInterface
  10. {
  11.     /**
  12.      * @var TranslatorInterface
  13.      */
  14.     private TranslatorInterface $tr;
  15.     /**
  16.      * @var Security
  17.      */
  18.     private Security $security;
  19.     /**
  20.      * @param TranslatorInterface $tr
  21.      * @param Security $security
  22.      */
  23.     public function __construct(
  24.         TranslatorInterface $tr,
  25.         Security $security
  26.     ) {
  27.         $this->tr $tr;
  28.         $this->security $security;
  29.     }
  30.     /**
  31.      * @return array
  32.      */
  33.     public static function getSubscribedEvents(): array
  34.     {
  35.         if (CheckBundleInstall::exist('statistics-bundle')) {
  36.             $reflectionClass = new ReflectionClass('Bluue\StatisticsBundle\Event\MenuStatisticPageEvent');
  37.             return [
  38.                 $reflectionClass->getConstant('NAME') => 'onLoad'
  39.             ];
  40.         }
  41.         return [];
  42.     }
  43.     /**
  44.      * @param object $event
  45.      * @return void
  46.      */
  47.     public function onLoad(object $event): void
  48.     {
  49.         if (!$this->security->isGranted('ROLE__PROJECTS__READ_ONLY')) {
  50.             return;
  51.         }
  52.         $pages $event->getPages();
  53.         $pages[] = [
  54.             'id' => 'projects_bundle__statistics',
  55.             'name' => $this->tr->trans('Time spent', [], 'ProjectsBundle')
  56.         ];
  57.         $event->setPages($pages);
  58.     }
  59. }