<?php
namespace App\Service\Abstract\Traits;
use App\Service\Utils\Options;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Core\User\UserInterface;
trait Main
{
/**
* @var EntityManagerInterface
*/
protected EntityManagerInterface $em;
/**
* @var Security
*/
protected Security $security;
/**
* @var Options
*/
protected Options $options;
/**
* @var UrlGeneratorInterface
*/
protected UrlGeneratorInterface $router;
/**
* @param EntityManagerInterface $em
* @param Security $security
* @param Options $options
* @param UrlGeneratorInterface $router
*/
public function __construct(
EntityManagerInterface $em,
Security $security,
Options $options,
UrlGeneratorInterface $router
) {
$this->em = $em;
$this->security = $security;
$this->options = $options;
$this->router = $router;
}
/**
* @return bool
*/
public function isLogged(): bool
{
if ($this->security->getUser()) {
return true;
}
return false;
}
/**
* @return UserInterface|null
*/
public function getUser(): ?UserInterface
{
return $this->security->getUser();
}
/**
* @return int|null
*/
public function getUserId(): ?int
{
return $this->getUser()?->getId();
}
/**
* @return int|null
*/
public function getUserRole(): ?int
{
return $this->getUser()?->getRoleId();
}
/**
* @return int|null
*/
public function getUserStatus(): ?int
{
return $this->getUser()?->getStatusId();
}
}