added RBAC

This commit is contained in:
Antonio Ramirez
2016-12-14 02:26:02 +01:00
parent 9409da4c89
commit 9f1a60b542
43 changed files with 1625 additions and 245 deletions

View File

@ -0,0 +1,25 @@
<?php
namespace Da\User\Validator;
use Da\User\Traits\AuthManagerTrait;
use Yii;
use yii\validators\Validator;
class RbacItemsValidator extends Validator
{
use AuthManagerTrait;
protected function validateValue($value)
{
if (!is_array($value)) {
return [Yii::t('item', 'Invalid value'), []];
}
foreach ($value as $item) {
if ($this->getAuthManager()->getItem($item) == null) {
return [Yii::t('user', 'There is neither role nor permission with name "{0}"', [$item]), []];
}
}
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace Da\User\Validator;
use ReflectionClass;
use Exception;
use yii\validators\Validator;
use Yii;
class RbacRuleValidator extends Validator
{
protected function validateValue($value)
{
try {
$class = new ReflectionClass($value);
} catch (Exception $e) {
return [Yii::t('user', 'Class "{0}" does not exist', $value), []];
}
if ($class->isInstantiable() == false) {
return [Yii::t('user', 'Rule class can not be instantiated'), []];
}
if ($class->isSubclassOf('\yii\rbac\Rule') == false) {
return [Yii::t('user', 'Rule class must extend "yii\rbac\Rule"'), []];
}
}
}