Final Class Yiisoft\Rbac\Php\AssignmentsStorage
| Inheritance | Yiisoft\Rbac\Php\AssignmentsStorage » Yiisoft\Rbac\SimpleAssignmentsStorage |
|---|---|
| Implements | Yiisoft\Rbac\Php\FileStorageInterface |
| Uses Traits | Yiisoft\Rbac\Php\FileStorageTrait |
Storage stores roles and permissions in PHP file specified in {@see AssignmentsStorage::$assignmentFile}.
It is suitable for authorization data that is not too big (for example, the authorization data for a personal blog system).
Public Methods
Method Details
| public mixed __construct ( string $filePath, callable|null $getFileUpdatedAt = null ) | ||
| $filePath | string | |
| $getFileUpdatedAt | callable|null | |
public function __construct(string $filePath, ?callable $getFileUpdatedAt = null)
{
$this->initFileProperties($filePath, $getFileUpdatedAt);
$this->load();
}
| public void add ( \Yiisoft\Rbac\Assignment $assignment ) | ||
| $assignment | \Yiisoft\Rbac\Assignment | |
public function add(Assignment $assignment): void
{
parent::add($assignment);
$this->save();
}
| public integer getFileUpdatedAt ( ) |
public function getFileUpdatedAt(): int
{
$getFileUpdatedAt = $this->getFileUpdatedAt;
$fileUpdatedAt = $getFileUpdatedAt($this->filePath);
if (!is_int($fileUpdatedAt)) {
throw new RuntimeException('getFileUpdatedAt callable must return a UNIX timestamp.');
}
return $fileUpdatedAt;
}
| public void load ( ) |
public function load(): void
{
parent::clear();
/** @psalm-var list<RawAssignment> $assignments */
$assignments = $this->loadFromFile($this->filePath);
if (empty($assignments)) {
return;
}
$fileUpdatedAt = $this->getFileUpdatedAt();
foreach ($assignments as $assignment) {
/** @psalm-suppress InvalidPropertyAssignmentValue */
$this->assignments[$assignment['user_id']][$assignment['item_name']] = new Assignment(
userId: $assignment['user_id'],
itemName: $assignment['item_name'],
createdAt: $assignment['created_at'] ?? $fileUpdatedAt,
);
}
}
| public void remove ( string $itemName, string $userId ) | ||
| $itemName | string | |
| $userId | string | |
public function remove(string $itemName, string $userId): void
{
if (!$this->exists($itemName, $userId)) {
return;
}
parent::remove($itemName, $userId);
$this->save();
}
| public void removeByItemName ( string $itemName ) | ||
| $itemName | string | |
public function removeByItemName(string $itemName): void
{
parent::removeByItemName($itemName);
$this->save();
}
| public void removeByUserId ( string $userId ) | ||
| $userId | string | |
public function removeByUserId(string $userId): void
{
parent::removeByUserId($userId);
$this->save();
}
Signup or Login in order to comment.