This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% if is_granted(‘add_content’) %} | |
<button>Add content</button> | |
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% if is_granted(‘ROLE_ADMIN’) %} | |
<button>Secret Button</button> | |
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
catch_all: | |
path: /{route} | |
requirements: | |
route: .* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
editor: | |
- add_content | |
moderator: | |
- moderate_content | |
admin: | |
- edit_user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//... | |
class PermissionUrlVoter implements VoterInterface | |
{ | |
//... | |
/** | |
* {@inheritdoc} | |
*/ | |
public function vote(TokenInterface $token, $object, array $attributes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//... | |
use ...CallableCompilerPass; | |
//... | |
protected function configurePasses(ContainerBuilder $c) | |
{ | |
$c->addCompilerPass(new CallableCompilerPass(function (ContainerBuilder $c) { | |
if (!$c->hasDefinition(‘security.access_map’)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//... | |
class PermissionUrlRequestMatcher implements RequestMatcherInterface | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public function matches(Request $request) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//... | |
class PermissionUrlMap | |
{ | |
/** | |
* Order matters, in that it will match the first one it comes across. So put more specific URLs higher up. | |
* | |
* @var array Format is [‘permission’ => ‘/path/to/page’] | |
*/ | |
public static $permissionMap = [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//... | |
$container->loadFromExtension(‘security’, [ | |
//... | |
‘access_control’ => [ | |
[‘path’ => ‘^/content/add’, ‘role’ => ‘add_content’], | |
[‘path’ => ‘^/content/moderate’, ‘role’ => ‘moderate_content’], | |
[‘path’ => ‘^/user/edit’, ‘role’ => ‘edit_user’] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//... | |
$container->loadFromExtension(‘security’, [ | |
//... | |
‘access_control’ => [ | |
[‘path’ => ‘^/content/add’, ‘role’ => ‘ROLE_EDITOR’], | |
[‘path’ => ‘^/content/moderate’, ‘role’ => ‘ROLE_MODERATOR’], | |
[‘path’ => ‘^/user/edit’, ‘role’ => ‘ROLE_ADMIN’] |