public function registerRole(Role $role, $connect = TRUE) { $this->roles[$role->getId()] = $role; if ($connect) { $role->connectToParent($this->roles); if (!$role->hasParent()) { $this->rootRoles[$role->getId()] = $role; } } }
protected function drawRole(OutputInterface $output, Trejjam\Authorization\Acl\Role $role, $depth = 0) { $output->writeln(Nette\Utils\Strings::padLeft('', $depth, ' ') . '\\_ ' . $role->getName()); $resource = []; /** @var Trejjam\Authorization\Acl\Resource $v */ foreach ($role->getResource() as $v) { $resource[] = $v->getNameRaw() . ":" . $v->getActionRaw(); } if (count($resource) > 0) { $output->writeln(Nette\Utils\Strings::padLeft('', $depth + 2, ' ') . "-" . implode(", ", $resource)); } /** @var Trejjam\Authorization\Acl\Role $v */ foreach ($role->getChild() as $v) { $this->drawRole($output, $v, $depth + 1); } }
protected function findCircle(Role $role, Role $parent) { if ($role->getId() == $parent->getId()) { return TRUE; } else { if ($parent->hasParent()) { return $this->findCircle($role, $parent->getParent()); } else { return FALSE; } } }
/** * @param Role $role */ protected function connectToChild(Role $role) { $this->child[$role->getId()] = $role; }
/** * @param Role[] $roles */ public function connectToRole($roles) { $this->role = $roles[$this->roleId]; $this->role->addResource($this); }