本文整理汇总了PHP中PolicySet::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP PolicySet::instance方法的具体用法?PHP PolicySet::instance怎么用?PHP PolicySet::instance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PolicySet
的用法示例。
在下文中一共展示了PolicySet::instance方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testAllPolicyEvaluateAllAny
/**
* Test the evaluation of all policies when no policy name is given
*/
public function testAllPolicyEvaluateAllAny()
{
$set = PolicySet::instance()->add('policy1', Policy::instance()->hasUsername('ccornutt'));
$user = (object) ['username' => 'ccornutt'];
$subject = new Subject($user);
$subject->setAuth(true);
$context = new Context(['policies' => $set]);
$gateway = new Gateway($subject, $context);
// Evaluate the result of the policy above, true because they're:
// 1. set correctly, 2. policy passes
$result = $gateway->evaluate();
$this->assertTrue($result);
}
示例2: testPolicyNameNotFoundAllows
/**
* Test that an exception is thrown when teh policy name isn't found
*
* @expectedException \InvalidArgumentException
*/
public function testPolicyNameNotFoundAllows()
{
$policySet = PolicySet::instance();
$subject = new Subject((object) ['username' => 'ccornutt']);
$en = new Enforcer($policySet);
$en->allows('policy1', $subject);
}