90 lines
2.1 KiB
PHP
90 lines
2.1 KiB
PHP
<?php
|
|
namespace Misuzu\Perms;
|
|
|
|
use Index\Data\IDbResult;
|
|
|
|
class PermissionInfo implements IPermissionResult {
|
|
use PermissionResultShared;
|
|
|
|
private int $calculated;
|
|
|
|
public function __construct(
|
|
private ?string $userId,
|
|
private ?string $roleId,
|
|
private ?string $forumCategoryId,
|
|
private string $category,
|
|
private int $allow,
|
|
private int $deny,
|
|
) {
|
|
$this->calculated = $this->allow & ~$this->deny;
|
|
}
|
|
|
|
public static function fromResult(IDbResult $result): PermissionInfo {
|
|
return new PermissionInfo(
|
|
userId: $result->getStringOrNull(0),
|
|
roleId: $result->getStringOrNull(1),
|
|
forumCategoryId: $result->getStringOrNull(2),
|
|
category: $result->getString(3),
|
|
allow: $result->getInteger(4),
|
|
deny: $result->getInteger(5),
|
|
);
|
|
}
|
|
|
|
public function hasUserId(): bool {
|
|
return $this->userId !== null;
|
|
}
|
|
|
|
public function getUserId(): ?string {
|
|
return $this->userId;
|
|
}
|
|
|
|
public function hasRoleId(): bool {
|
|
return $this->roleId !== null;
|
|
}
|
|
|
|
public function getRoleId(): ?string {
|
|
return $this->roleId;
|
|
}
|
|
|
|
public function hasForumCategoryId(): bool {
|
|
return $this->forumCategoryId !== null;
|
|
}
|
|
|
|
public function getForumCategoryId(): ?string {
|
|
return $this->forumCategoryId;
|
|
}
|
|
|
|
public function getCategory(): string {
|
|
return $this->category;
|
|
}
|
|
|
|
public function getAllow(): int {
|
|
return $this->allow;
|
|
}
|
|
|
|
public function getDeny(): int {
|
|
return $this->deny;
|
|
}
|
|
|
|
public function getCalculated(): int {
|
|
return $this->calculated;
|
|
}
|
|
|
|
public function check(int $perm): bool {
|
|
return ($this->calculated & $perm) > 0;
|
|
}
|
|
|
|
public function checkAllow(int $perm): bool {
|
|
return ($this->allow & $perm) > 0;
|
|
}
|
|
|
|
public function checkDeny(int $perm): bool {
|
|
return ($this->deny & $perm) > 0;
|
|
}
|
|
|
|
public function checkNeutral(int $perm): bool {
|
|
return ($this->allow & $perm) === 0
|
|
&& ($this->deny & $perm) === 0;
|
|
}
|
|
}
|