addParent() public method

Add parent to ancestor
public addParent ( Permission $parent ) : void
$parent Permission parent instance
return void
Exemplo n.º 1
0
 /**
  * Add parent to ancestor
  *
  * @param Permission $parent parent instance
  * @return void
  */
 public function addParent(Permission $parent)
 {
     if ($this->isParent($parent) === true) {
         $this->parent = $parent;
     } elseif ($this->parent !== null) {
         $this->parent->addParent($parent);
     }
 }
 /**
  * Set permission's ancestor to permission
  *
  * @param Permission $permission permission instance
  * @return void
  */
 protected function setAncestor(Permission $permission)
 {
     $ancestors = $this->repo->fetchAncestor($permission->siteKey, $permission->name);
     usort($ancestors, function (Permission $a, Permission $b) {
         if ($a->getDepth() == $b->getDepth()) {
             return 0;
         }
         return $a->getDepth() > $b->getDepth() ? -1 : 1;
     });
     foreach ($ancestors as $ancestor) {
         $permission->addParent($ancestor);
     }
 }