Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace App\EventListener;
- use App\Entity\Counting;
- use App\Entity\User;
- use Doctrine\ORM\Event\PrePersistEventArgs;
- use Symfony\Component\Security\Core\Security;
- class CountingEventListener
- {
- /**
- * @var Security
- */
- private $security;
- /**
- * @param Security $security
- */
- public function __construct(Security $security)
- {
- $this->security = $security;
- }
- public function prePersist(Counting $counting, PrePersistEventArgs $event)
- {
- if (null === $user = $this->security->getUser()) {
- return;
- }
- if ($this->security->isGranted('ROLE_ADMIN')) {
- return;
- }
- if ($this->security->isGranted('ROLE_MANAGER')) {
- $counting->setManager($user);
- return;
- }
- if ($this->security->isGranted('ROLE_USER')) {
- $counting->setPolicyHolder($user);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement