Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrea Bergamasco vjandrea

View GitHub Profile
@vjandrea
vjandrea / AccessChecker.php
Last active Jul 29, 2021 — forked from leotiger/allowed_roles_for_route.md
Symfony 4: Check if a route is accessible to a User based on their roles
View AccessChecker.php
<?php
/**
* @Author Andrea Bergamasco <andrea@bergamasco.me>
* Inspired by @leotiger: https://gist.github.com/leotiger/ca496d1b16c30afea060904bd5e78714
*
* Usage:
* $token = $this->security->getToken();
* $this->accessChecker->userTokenCanAccessRoute($token, 'admin.index');
*/