vendor/symfony/security-core/Authorization/Voter/TraceableVoter.php line 42

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Security\Core\Authorization\Voter;
  11. use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
  12. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  13. use Symfony\Component\Security\Core\Event\VoteEvent;
  14. use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
  15. /**
  16.  * Decorates voter classes to send result events.
  17.  *
  18.  * @author Laurent VOULLEMIER <laurent.voullemier@gmail.com>
  19.  *
  20.  * @internal
  21.  */
  22. class TraceableVoter implements VoterInterface
  23. {
  24.     private $voter;
  25.     private $eventDispatcher;
  26.     public function __construct(VoterInterface $voterEventDispatcherInterface $eventDispatcher)
  27.     {
  28.         $this->voter $voter;
  29.         if (class_exists(LegacyEventDispatcherProxy::class)) {
  30.             $this->eventDispatcher LegacyEventDispatcherProxy::decorate($eventDispatcher);
  31.         } else {
  32.             $this->eventDispatcher $eventDispatcher;
  33.         }
  34.     }
  35.     public function vote(TokenInterface $token$subject, array $attributes): int
  36.     {
  37.         $result $this->voter->vote($token$subject$attributes);
  38.         $this->eventDispatcher->dispatch(new VoteEvent($this->voter$subject$attributes$result), 'debug.security.authorization.vote');
  39.         return $result;
  40.     }
  41.     public function getDecoratedVoter(): VoterInterface
  42.     {
  43.         return $this->voter;
  44.     }
  45. }