首页 > 代码库 > Yii\rbac\BaseManager add($object) 即auth->add()

Yii\rbac\BaseManager add($object) 即auth->add()

    /**
     * @inheritdoc
     */
    public function add($object)
    {
        if ($object instanceof Item) { //①如果是role或permission对象就创建auth_rule
            if ($object->ruleName && $this->getRule($object->ruleName) === null) { //如果规则是空的 就创建规则
                $rule = \Yii::createObject($object->ruleName);
                $rule->name = $object->ruleName;
                $this->addRule($rule);
            }
            return $this->addItem($object);
        } elseif ($object instanceof Rule) {
            return $this->addRule($object);
        } else {
            throw new InvalidParamException(‘Adding unsupported object type.‘);
        }
    }

 

 

Yii\rbac\BaseManager add($object) 即auth->add()