예제 #1
0
 /**
  * Adds an interface.
  *
  * If the interface is passed as PhpInterface object,
  * the interface is also added as use statement.
  *
  * @param PhpInterface|string $interface interface or qualified name
  * @return $this
  */
 public function addInterface($interface)
 {
     if ($interface instanceof PhpInterface) {
         $name = $interface->getName();
         $qname = $interface->getQualifiedName();
         $namespace = $interface->getNamespace();
         if ($namespace != $this->getNamespace()) {
             $this->addUseStatement($qname);
         }
     } else {
         $name = $interface;
     }
     $this->interfaces->add($name);
     return $this;
 }
예제 #2
0
 /**
  * Returns a set of allowed action ids
  *
  * @param User $user
  * @return Set
  */
 private function getPermissionTable(User $user)
 {
     $userId = $user->getId();
     if ($this->permissionTable->has($userId)) {
         return $this->permissionTable->get($userId);
     }
     // always allow what guests can do
     $guestGroup = GroupQuery::create()->findOneByIsGuest(true);
     // collect groups from user
     $groups = GroupQuery::create()->filterByUser($user)->find();
     $userGroup = GroupQuery::create()->filterByOwnerId($userId)->findOne();
     if ($userGroup) {
         $groups[] = $userGroup;
     }
     $groups[] = $guestGroup;
     // ... structure them
     $permissionTable = new Set();
     foreach ($groups as $group) {
         foreach ($group->getActions() as $action) {
             $permissionTable->add($action->getId());
         }
     }
     $this->permissionTable->set($userId, $permissionTable);
     return $this->permissionTable->get($userId);
 }
예제 #3
0
 public function calculateGeneration(Skill $skill)
 {
     if ($this->processedGenerationSkills->contains($skill)) {
         return;
     }
     $this->lineage = [];
     $generation = 1;
     $ancestors = $this->getAncestors($skill);
     if (count($ancestors)) {
         $root = $this->findRoot($ancestors);
         if ($root !== null) {
             $generation = $this->nextStep($root, $skill, $ancestors);
         }
     }
     $skill->setGeneration($generation);
     $skill->clearLineagesRelatedBySkillId();
     // set generations
     foreach ($this->lineage as $pos => $ancestor) {
         $lin = new Lineage();
         $lin->setSkill($skill);
         $lin->setAncestor($ancestor);
         $lin->setPosition($pos);
     }
     $this->modifiedSkills->add($skill);
     $this->processedGenerationSkills->add($skill);
     $this->processGenerationQueue();
 }
예제 #4
0
 public function testDuplicateValues()
 {
     $item1 = 'item 1';
     $set = new Set();
     $set->add($item1)->add($item1)->add($item1);
     $this->assertEquals(1, $set->size());
 }
 /**
  * Adds a new required file
  *
  * @param string $file
  * @return $this
  */
 public function addRequiredFile($file)
 {
     $this->requiredFiles->add($file);
     return $this;
 }
예제 #6
0
 public function addAcl($group)
 {
     $this->acl->add($group);
     return $this;
 }