示例#1
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);
 }
 public function testFilter()
 {
     $set = new Set([1, 2, 3, 4, 5, 6]);
     $set2 = $set->filter(function ($item) {
         return $item & 1;
     });
     $this->assertSame([1, 3, 5], $set2->toArray());
 }
示例#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();
 }
 /**
  * Removes an interface.
  *
  * If the interface is passed as PhpInterface object,
  * the interface is also remove from the use statements.
  *
  * @param PhpInterface|string $interface interface or qualified name
  * @return $this
  */
 public function removeInterface($interface)
 {
     if ($interface instanceof PhpInterface) {
         $name = $interface->getName();
         $qname = $interface->getQualifiedName();
         $this->removeUseStatement($qname);
     } else {
         $name = $interface;
     }
     $this->interfaces->remove($name);
     return $this;
 }
 /**
  * Adds a new required file
  *
  * @param string $file
  * @return $this
  */
 public function addRequiredFile($file)
 {
     $this->requiredFiles->add($file);
     return $this;
 }
示例#6
0
 public function setAcl(array $groups)
 {
     $this->acl->clear();
     $this->acl->addAll($groups);
     return $this;
 }
示例#7
0
 /**
  * @param string $name
  * @return Startgroup
  */
 private function getStartgroup($name)
 {
     $name = $this->translate($name);
     // some special cases
     $competition = null;
     if ($name == 'Junior Expert (male)' || $name == 'Expert (male)') {
         $competition = $this->competitions->get('Individual Freestyle (male)');
         $startgroupName = str_replace(' (male)', '', $name);
     } else {
         if ($name == 'Junior Expert (female)' || $name == 'Expert (female)') {
             $competition = $this->competitions->get('Individual Freestyle (female)');
             $startgroupName = str_replace(' (female)', '', $name);
         }
     }
     if ($competition === null) {
         $words = new Set();
         foreach (array_values($this->translations) as $names) {
             $words->addAll(Text::create($names)->split(' '));
         }
         $startgroupName = trim(str_replace($words->toArray(), '', $name));
         $words = Text::create($startgroupName)->split(' ');
         $competitionName = preg_replace('/\\s\\s+/', ' ', trim(str_replace($words->toArray(), '', $name)));
         if (!$this->competitions->has($competitionName)) {
             throw new \Exception('Cannot find competition for ' . $competitionName);
         }
         $competition = $this->competitions->get($competitionName);
     }
     $startgroup = new Startgroup();
     $startgroup->setName($startgroupName);
     $startgroup->setSlug(NameUtils::dasherize(strtolower($startgroupName)));
     $startgroup->setCompetition($competition);
     return $startgroup;
 }
示例#8
0
 public function isModifier(Token $token)
 {
     return $this->modifier->contains($token->type);
 }