An authorization item can be an operation, a task or a role. They form an authorization hierarchy. Items on higher levels of the hierarchy inherit the permissions represented by items on lower levels. A user may be assigned one or several authorization items (called Assignment assignments). He can perform an operation only when it is among his assigned items.
Since: 2.0
Author: Qiang Xue (qiang.xue@gmail.com)
Author: Alexander Kochetov (creocoder@gmail.com)
Inheritance: extends yii\base\Object
 /**
  * Saves an authorization item to persistent storage.
  * @param Item $item the item to be saved.
  * @param string $oldName the old item name. If null, it means the item name is not changed.
  */
 public function saveItem($item, $oldName = null)
 {
     if ($this->usingSqlite() && $oldName !== null && $item->getName() !== $oldName) {
         $this->db->createCommand()->update($this->itemChildTable, ['parent' => $item->getName()], ['parent' => $oldName])->execute();
         $this->db->createCommand()->update($this->itemChildTable, ['child' => $item->getName()], ['child' => $oldName])->execute();
         $this->db->createCommand()->update($this->assignmentTable, ['item_name' => $item->getName()], ['item_name' => $oldName])->execute();
     }
     $this->db->createCommand()->update($this->itemTable, ['name' => $item->getName(), 'type' => $item->type, 'description' => $item->description, 'biz_rule' => $item->bizRule, 'data' => $item->data === null ? null : serialize($item->data)], ['name' => $oldName === null ? $item->getName() : $oldName])->execute();
 }
 /**
  * Saves an authorization item to persistent storage.
  * @param Item $item the item to be saved.
  * @param string $oldName the old item name. If null, it means the item name is not changed.
  * @throws InvalidParamException if an item with the same name already taken
  */
 public function saveItem($item, $oldName = null)
 {
     if ($oldName !== null && ($newName = $item->getName()) !== $oldName) {
         // name changed
         if (isset($this->_items[$newName])) {
             throw new InvalidParamException("Unable to change the item name. The name '{$newName}' is already used by another item.");
         }
         if (isset($this->_items[$oldName]) && $this->_items[$oldName] === $item) {
             unset($this->_items[$oldName]);
             $this->_items[$newName] = $item;
             if (isset($this->_children[$oldName])) {
                 $this->_children[$newName] = $this->_children[$oldName];
                 unset($this->_children[$oldName]);
             }
             foreach ($this->_children as &$children) {
                 if (isset($children[$oldName])) {
                     $children[$newName] = $children[$oldName];
                     unset($children[$oldName]);
                 }
             }
             foreach ($this->_assignments as &$assignments) {
                 if (isset($assignments[$oldName])) {
                     $assignments[$newName] = $assignments[$oldName];
                     unset($assignments[$oldName]);
                 }
             }
         }
     }
 }