コード例 #1
0
 public function testEvaluate_hasPermission_correctResult()
 {
     $object = new \stdClass();
     $securityContext = \Mockery::mock()->shouldReceive('isGranted')->with('read', $object)->andReturn(true)->once()->getMock();
     $language = new ExpressionLanguage();
     $evaluated = $language->evaluate("hasPermission(object, 'read')", ['object' => $object, 'securityContext' => $securityContext]);
     $this->assertTrue($evaluated);
 }
コード例 #2
0
ファイル: ExpressionVoter.php プロジェクト: zycon42/security
 /**
  * {@inheritdoc}
  */
 public function vote(IIdentity $identity, array $attributes, $object)
 {
     $result = self::VOTE_ABSTAIN;
     $variables = null;
     foreach ($attributes as $attribute) {
         if (!$this->supportsAttribute($attribute)) {
             continue;
         }
         if ($variables === null) {
             $variables = $this->getVariables($identity, $object);
         }
         $result = self::VOTE_DENIED;
         if ($this->language->evaluate($attribute, $variables)) {
             return self::VOTE_GRANTED;
         }
     }
     return $result;
 }
コード例 #3
0
 public function evaluate(Expression $expression, Request $request)
 {
     return $this->language->evaluate($expression, $this->getVariables($request));
 }