示例#1
0
 public function testGetParentRole()
 {
     $parent = new Feature();
     $parent->setRole('ROLE_USER');
     $this->entity->setParent($parent);
     $this->assertEquals('ROLE_USER', $this->entity->getParentRole());
 }
 /**
  * @param string  $name   Feature name
  * @param Feature $parent Parent Feature
  *
  * @return Feature
  */
 public function create($name, Feature $parent = null)
 {
     $feature = new Feature();
     $feature->setName($name);
     if ($parent) {
         $feature->setParent($parent);
     }
     return $feature;
 }
 /**
  * @param Feature $feature
  *
  * @return bool
  */
 public function isGranted(Feature $feature)
 {
     if (null === $this->context) {
         return false;
     }
     if (!$feature->isEnabled()) {
         return false;
     }
     if ($feature->getRole()) {
         if (!$this->context->isGranted($feature->getRole())) {
             return false;
         }
     }
     if ('' !== trim($feature->getParentRole())) {
         if (!$this->context->isGranted($feature->getParentRole())) {
             return false;
         }
     }
     return true;
 }