Abstract Class Yiisoft\Rbac\SimpleAssignmentsStorage
| Inheritance | Yiisoft\Rbac\SimpleAssignmentsStorage |
|---|---|
| Implements | Yiisoft\Rbac\AssignmentsStorageInterface |
Psalm Types
| Name | Value |
|---|---|
| RawAssignment | array{item_name: string, user_id: string, created_at: integer} |
Protected Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| $assignments | array | Yiisoft\Rbac\SimpleAssignmentsStorage |
Public Methods
Property Details
Method Details
| public void add ( Yiisoft\Rbac\Assignment $assignment ) | ||
| $assignment | Yiisoft\Rbac\Assignment | |
public function add(Assignment $assignment): void
{
$this->assignments[$assignment->getUserId()][$assignment->getItemName()] = $assignment;
}
| public boolean exists ( string $itemName, string $userId ) | ||
| $itemName | string | |
| $userId | string | |
public function exists(string $itemName, string $userId): bool
{
return isset($this->getByUserId($userId)[$itemName]);
}
| public array filterUserItemNames ( string $userId, array $itemNames ) | ||
| $userId | string | |
| $itemNames | array | |
public function filterUserItemNames(string $userId, array $itemNames): array
{
$assignments = $this->getByUserId($userId);
if (empty($assignments)) {
return [];
}
$userItemNames = [];
foreach ($itemNames as $itemName) {
if (array_key_exists($itemName, $assignments)) {
$userItemNames[] = $itemName;
}
}
return $userItemNames;
}
| public Yiisoft\Rbac\Assignment|null get ( string $itemName, string $userId ) | ||
| $itemName | string | |
| $userId | string | |
public function get(string $itemName, string $userId): ?Assignment
{
return $this->getByUserId($userId)[$itemName] ?? null;
}
| public array getByItemNames ( array $itemNames ) | ||
| $itemNames | array | |
public function getByItemNames(array $itemNames): array
{
$result = [];
foreach ($this->assignments as $assignments) {
foreach ($assignments as $userAssignment) {
if (in_array($userAssignment->getItemName(), $itemNames, true)) {
$result[] = $userAssignment;
}
}
}
return $result;
}
| public array getByUserId ( string $userId ) | ||
| $userId | string | |
public function getByUserId(string $userId): array
{
return $this->assignments[$userId] ?? [];
}
| public boolean hasItem ( string $name ) | ||
| $name | string | |
public function hasItem(string $name): bool
{
foreach ($this->getAll() as $assignmentInfo) {
if (array_key_exists($name, $assignmentInfo)) {
return true;
}
}
return false;
}
| public void remove ( string $itemName, string $userId ) | ||
| $itemName | string | |
| $userId | string | |
public function remove(string $itemName, string $userId): void
{
unset($this->assignments[$userId][$itemName]);
}
| public void removeByItemName ( string $itemName ) | ||
| $itemName | string | |
public function removeByItemName(string $itemName): void
{
foreach ($this->assignments as &$assignments) {
unset($assignments[$itemName]);
}
}
| public void removeByUserId ( string $userId ) | ||
| $userId | string | |
public function removeByUserId(string $userId): void
{
$this->assignments[$userId] = [];
}
| public void renameItem ( string $oldName, string $newName ) | ||
| $oldName | string | |
| $newName | string | |
public function renameItem(string $oldName, string $newName): void
{
if ($oldName === $newName) {
return;
}
foreach ($this->assignments as &$assignments) {
if (isset($assignments[$oldName])) {
$assignments[$newName] = $assignments[$oldName]->withItemName($newName);
unset($assignments[$oldName]);
}
}
}
| public boolean userHasItem ( string $userId, array $itemNames ) | ||
| $userId | string | |
| $itemNames | array | |
public function userHasItem(string $userId, array $itemNames): bool
{
$assignments = $this->getByUserId($userId);
if (empty($assignments)) {
return false;
}
foreach ($itemNames as $itemName) {
if (array_key_exists($itemName, $assignments)) {
return true;
}
}
return false;
}
Signup or Login in order to comment.