Example #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"'));
         }
     }]];
 }
Example #2
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [['user_id', 'required'], ['items', RbacValidator::className()], ['user_id', 'integer']];
 }
Example #3
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [['name', 'required'], [['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 () {
         $rule = $this->manager->getRule($this->rule);
         if (!$rule) {
             $this->addError('rule', \Yii::t('rbac', 'Rule {0} does not exist', $this->rule));
         }
     }], ['data', function () {
         try {
             Json::decode($this->data);
         } catch (InvalidParamException $e) {
             $this->addError('data', \Yii::t('rbac', 'Data must be type of JSON ({0})', $e->getMessage()));
         }
     }]];
 }