Skip to content

Instantly share code, notes, and snippets.

@theMadness
Created November 14, 2018 20:03
Show Gist options
  • Save theMadness/b05c722d40861bdb36e6f5ae4d3b5392 to your computer and use it in GitHub Desktop.
Save theMadness/b05c722d40861bdb36e6f5ae4d3b5392 to your computer and use it in GitHub Desktop.
<?php
namespace AppBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class OverrideServiceCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
// @TODO: Add parameter check for an enabling flag
if ($container->hasParameter('security.role_hierarchy.roles')) {
$roles = $container->getParameter('security.role_hierarchy.roles');
$roles['ROLE_TO_EXTEND'][] = 'ROLE_CAN_EDIT_SOME_RESOURCE';
$roles['ROLE_TO_EXTEND'][] = 'ROLE_CAN_DELETE_SOME_RESOURCE';
$container->setParameter('security.role_hierarchy.roles', $roles);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment