Пример #1
0
 /** @inheritdoc */
 public function rules()
 {
     return [['name', 'required'], ['name', 'match', 'pattern' => '/^[\\w][\\w-.:]+[\\w]$/'], [['name', 'description', 'rule'], 'trim'], ['name', function () {
         if ($this->manager->getItem($this->name) !== null) {
             $this->addError('name', \Yii::t('rbac', 'Auth item with such name already exists'));
         }
     }, 'when' => function () {
         return $this->scenario == 'create' || $this->item->name != $this->name;
     }], ['children', RbacValidator::className()], ['rule', function () {
         try {
             $class = new \ReflectionClass($this->rule);
         } catch (\Exception $ex) {
             $this->addError('rule', \Yii::t('rbac', 'Class "{0}" does not exist', $this->rule));
             return;
         }
         if ($class->isInstantiable() == false) {
             $this->addError('rule', \Yii::t('rbac', 'Rule class can not be instantiated'));
         }
         if ($class->isSubclassOf('\\yii\\rbac\\Rule') == false) {
             $this->addError('rule', \Yii::t('rbac', 'Rule class must extend "yii\\rbac\\Rule"'));
         }
     }]];
 }
Пример #2
0
 /** @inheritdoc */
 public function rules()
 {
     return [['user_id', 'required'], ['items', RbacValidator::className()], ['user_id', 'integer']];
 }