yii\rbac\PhpManager::detectLoop PHP Method

detectLoop() protected method

Checks whether there is a loop in the authorization item hierarchy.
protected detectLoop ( Item $parent, Item $child ) : boolean
$parent Item parent item
$child Item the child item that is to be added to the hierarchy
return boolean whether a loop exists
    protected function detectLoop($parent, $child)
    {
        if ($child->name === $parent->name) {
            return true;
        }
        if (!isset($this->children[$child->name], $this->items[$parent->name])) {
            return false;
        }
        foreach ($this->children[$child->name] as $grandchild) {
            /* @var $grandchild Item */
            if ($this->detectLoop($parent, $grandchild)) {
                return true;
            }
        }
        return false;
    }