Skip to content

Commit

Permalink
voter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lbarulski committed Apr 29, 2014
1 parent b214121 commit 2069794
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
3 changes: 3 additions & 0 deletions DependencyInjection/Compiler/GateKeeperCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public function process(ContainerBuilder $container)
return;
}

$definition = $container->getDefinition('gatekeeper.voter');
$definition->addArgument(new Reference($container->getParameter('gatekeeper.provider.service')));

$definition = $container->getDefinition('gatekeeper');
$definition->addArgument(new Reference($container->getParameter('gatekeeper.repository.service')));

Expand Down
3 changes: 3 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public function getConfigTreeBuilder()
->scalarNode('repository_service')
->defaultValue('gatekeeper.repository.dummy')
->end()
->scalarNode('provider_service')
->defaultValue('gatekeeper.gates_provider.dummy')
->end()
->end();

return $treeBuilder;
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/GateKeeperExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function load(array $configs, ContainerBuilder $container)
$config = $this->processConfiguration($configuration, $configs);

$container->setParameter('gatekeeper.repository.service', $config['repository_service']);
$container->setParameter('gatekeeper.provider.service', $config['provider_service']);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
Expand Down
2 changes: 1 addition & 1 deletion Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ services:

gatekeeper.voter:
class: GateKeeperBundle\Voter\GateKeeper
arguments: [@gatekeeper, @gatekeeper.gates_provider.dummy]
arguments: [@gatekeeper]
tags:
- { name: security.voter }

Expand Down
9 changes: 2 additions & 7 deletions Voter/GateKeeper.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ public function __construct(Keeper $gateKeeper, GatesProviderInterface $gatesPro
*/
public function supportsAttribute($attribute)
{
if (null === $this->gates)
{
$this->gates = $this->gatesProvider->getGates();
}

return in_array($attribute, $this->gates);
return strpos($attribute, 'GATE_') === 0;
}

/**
Expand Down Expand Up @@ -92,7 +87,7 @@ public function vote(TokenInterface $token, $object, array $attributes)
}

$user = $token->getUser() instanceof ObjectInterface ? $token->getUser() : null;
$attributes = is_array($object) ? $object : [];
$object = is_array($object) ? $object : [];

if ($this->gateKeeper->hasAccess($attributes[0], $user, $object))
{
Expand Down

0 comments on commit 2069794

Please sign in to comment.