Skip to content

Instantly share code, notes, and snippets.

@c9s
Created August 11, 2015 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c9s/b070b5747d068ce0365b to your computer and use it in GitHub Desktop.
Save c9s/b070b5747d068ce0365b to your computer and use it in GitHub Desktop.
<?php
use Kendo\DefinitionStorage;
use SimpleApp\SimpleDefinition;
use SimpleApp\User\NormalUser;
use Kendo\RuleLoader\RuleLoader;
use Kendo\RuleLoader\DefinitionRuleLoader;
use Kendo\RuleMatcher\AccessRuleMatcher;
use Kendo\Operation\CommonOperation;
use Kendo\IdentifierProvider\ActorIdentifierProvider;
use Kendo\Operation\CommonOperation as Op;
class AuthorizerTest extends PHPUnit_Framework_TestCase
{
public function testRuleMatcherChain()
{
$storage = new DefinitionStorage;
$storage->add(new SimpleDefinition);
$loader = new DefinitionRuleLoader;
$loader->load($storage);
$accessRuleMatcher = new AccessRuleMatcher($loader);
$dynamicRuleMatcher = new DynamicRuleMatcher([
new MyDynamicRule,
new YourDynamicRule,
new AnyDynamicRule,
new AnotherDynamicRule,
new TheOtherDynamicRule,
]);
$authorizer = new Authorizer;
$authorizer->addMatcher($accessRuleMatcher);
$authorizer->addMatcher($dynamicRuleMatcher);
$actor = new NormalUser;
$authentication = $authorizer->authorize($actor, Op::CREATE, 'products');
if ($authentication->isAllowed()) {
} else {
throw new GrantAccessFailedException($authentication->getMessage(), $authentication->getReason());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment