Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Exception\LogicException;

/**
* Adds all configured security voters to the access decision manager.
Expand All @@ -40,6 +41,10 @@ public function process(ContainerBuilder $container)
$voters = iterator_to_array($voters);
ksort($voters);

$container->getDefinition('security.access.decision_manager')->replaceArgument(0, array_values($voters));
if (!$voters) {
throw new LogicException('No security voters found. You need to tag at least one with "security.voter"');
}

$container->getDefinition('security.access.decision_manager')->addMethodCall('setVoters', array(array_values($voters)));
}
}
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/SecurityBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
],
"require": {
"php": ">=5.3.9",
"symfony/security": "~2.7|~3.0.0",
"symfony/security": "~2.8|~3.0.0",
"symfony/http-kernel": "~2.2|~3.0.0"
},
"require-dev": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,8 @@ class AccessDecisionManager implements AccessDecisionManagerInterface
*
* @throws \InvalidArgumentException
*/
public function __construct(array $voters, $strategy = self::STRATEGY_AFFIRMATIVE, $allowIfAllAbstainDecisions = false, $allowIfEqualGrantedDeniedDecisions = true)
public function __construct(array $voters = array(), $strategy = self::STRATEGY_AFFIRMATIVE, $allowIfAllAbstainDecisions = false, $allowIfEqualGrantedDeniedDecisions = true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how it would make a difference anyway, but we don't need to make this option - the "old" way would of course also allow an empty array.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not required, but if setting no voters on instantiation is allowed, I thought it would be more consistent to make the argument optional also.

{
if (!$voters) {
throw new \InvalidArgumentException('You must at least add one voter.');
}

$strategyMethod = 'decide'.ucfirst($strategy);
if (!is_callable(array($this, $strategyMethod))) {
throw new \InvalidArgumentException(sprintf('The strategy "%s" is not supported.', $strategy));
Expand All @@ -58,6 +54,16 @@ public function __construct(array $voters, $strategy = self::STRATEGY_AFFIRMATIV
$this->allowIfEqualGrantedDeniedDecisions = (bool) $allowIfEqualGrantedDeniedDecisions;
}

/**
* Configures the voters.
*
* @param VoterInterface[] $voters An array of VoterInterface instances
*/
public function setVoters(array $voters)
{
$this->voters = $voters;
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ public function testSupportsAttribute()
$this->assertFalse($manager->supportsAttribute('foo'));
}

/**
* @expectedException \InvalidArgumentException
*/
public function testSetVotersEmpty()
{
$manager = new AccessDecisionManager(array());
}

/**
* @expectedException \InvalidArgumentException
*/
Expand Down