yii\rbac\BaseManager::createRole PHP Метод

createRole() публичный Метод

public createRole ( $name )
    public function createRole($name)
    {
        $role = new Role();
        $role->name = $name;
        return $role;
    }

Usage Example

Пример #1
0
 /**
  * Creating items object using given config data collection
  *
  * @param array $collection
  * @throws InvalidConfigException
  */
 protected function generateItems(array $collection)
 {
     $this->_items = [];
     $this->_children = [];
     foreach ($collection as $c) {
         /** @var ConfigBase $c */
         if (!$c instanceof ConfigBase) {
             throw new \RuntimeException('Invalid configuration source given.');
         }
         foreach ($c->getData() as $key => $value) {
             if (is_array($value)) {
                 if (count($value) == 1 && isset($value['children']) && is_array($value['children'])) {
                     if (!isset($this->_children[$key])) {
                         $this->_children[$key] = [];
                     }
                     foreach ($value['children'] as $kid) {
                         $this->_children[$key][] = $kid;
                     }
                     continue;
                 }
                 if (!isset($value['type'])) {
                     throw new InvalidConfigException('Please specify type for ' . $key . ' auth item!');
                 }
                 if ($value['type'] == Item::TYPE_ROLE) {
                     $item = $this->_auth->createRole($key);
                 } elseif ($value['type'] == Item::TYPE_PERMISSION) {
                     $item = $this->_auth->createPermission($key);
                 } else {
                     throw new InvalidConfigException('Wrong type for ' . $key . ' auth item! Type can be ' . Item::TYPE_ROLE . ' (role) or ' . Item::TYPE_PERMISSION . ' (permission).');
                 }
                 $item->description = isset($value['description']) ? $value['description'] : null;
                 $item->data = isset($value['data']) ? $value['data'] : null;
                 if (isset($value['rule']) && $value['rule'] instanceof Rule) {
                     /** @var Rule $rule */
                     $rule = $value['rule'];
                     $rule->updatedAt = time();
                     $item->ruleName = !empty($rule->name) ? $rule->name : $rule::className();
                     $this->_items[$item->ruleName] = $rule;
                 }
                 if (isset($value['children']) && is_array($value['children'])) {
                     if (!isset($this->_children[$key])) {
                         $this->_children[$key] = [];
                     }
                     foreach ($value['children'] as $kid) {
                         $this->_children[$key][] = $kid;
                     }
                 }
             } else {
                 $item = $this->_auth->createPermission($key);
                 $item->description = $value;
             }
             $this->_items[$key] = $item;
         }
     }
 }
All Usage Examples Of yii\rbac\BaseManager::createRole