src/Service/Abstract/Traits/Main.php line 66

Open in your IDE?
  1. <?php
  2. namespace App\Service\Abstract\Traits;
  3. use App\Service\Utils\Options;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  6. use Symfony\Component\Security\Core\Security;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. trait Main
  9. {
  10.     /**
  11.      * @var EntityManagerInterface
  12.      */
  13.     protected EntityManagerInterface $em;
  14.     /**
  15.      * @var Security
  16.      */
  17.     protected Security $security;
  18.     /**
  19.      * @var Options
  20.      */
  21.     protected Options $options;
  22.     /**
  23.      * @var UrlGeneratorInterface
  24.      */
  25.     protected UrlGeneratorInterface $router;
  26.     /**
  27.      * @param EntityManagerInterface $em
  28.      * @param Security               $security
  29.      * @param Options                $options
  30.      * @param UrlGeneratorInterface  $router
  31.      */
  32.     public function __construct(
  33.         EntityManagerInterface $em,
  34.         Security $security,
  35.         Options $options,
  36.         UrlGeneratorInterface $router
  37.     ) {
  38.         $this->em $em;
  39.         $this->security $security;
  40.         $this->options $options;
  41.         $this->router $router;
  42.     }
  43.     /**
  44.      * @return bool
  45.      */
  46.     public function isLogged(): bool
  47.     {
  48.         if ($this->security->getUser()) {
  49.             return true;
  50.         }
  51.         return false;
  52.     }
  53.     /**
  54.      * @return UserInterface|null
  55.      */
  56.     public function getUser(): ?UserInterface
  57.     {
  58.         return $this->security->getUser();
  59.     }
  60.     /**
  61.      * @return int|null
  62.      */
  63.     public function getUserId(): ?int
  64.     {
  65.         return $this->getUser()?->getId();
  66.     }
  67.     /**
  68.      * @return int|null
  69.      */
  70.     public function getUserRole(): ?int
  71.     {
  72.         return $this->getUser()?->getRoleId();
  73.     }
  74.     /**
  75.      * @return int|null
  76.      */
  77.     public function getUserStatus(): ?int
  78.     {
  79.         return $this->getUser()?->getStatusId();
  80.     }
  81. }