I\'m in the process of upgrading Symfony from 2.8 to 3.4 and I have a Authentication Listener.
The constructor of the listener
public function __co
Inject AuthorizationChecker to your class
protected $authChecker;
public function __construct(AuthorizationChecker $authChecker)
{
$this->authChecker = $authChecker;
}
By injecting it in your service.yml
XXXXXXXXX:
class: App\XXX\XXXX\XXXXX
arguments: [ "@security.authorization_checker" ]
And then use it to check role using isGranted
if ($this->authChecker->isGranted('IS_AUTHENTICATED_ANONYMOUSLY')) {
}