mirror of
https://github.com/sitelease/sugar-cube-client.git
synced 2025-10-31 20:12:29 +01:00
113 lines
3.0 KiB
PHP
113 lines
3.0 KiB
PHP
<?php declare(strict_types=1);
|
|
namespace Gitea\Models;
|
|
|
|
/**
|
|
* Represents a set of permissions.
|
|
*/
|
|
class Permission implements \JsonSerializable {
|
|
|
|
/**
|
|
* @var bool Value indicating whether administrator access is allowed.
|
|
*/
|
|
private $admin;
|
|
|
|
/**
|
|
* @var bool Value indicating whether pull is allowed.
|
|
*/
|
|
private $pull;
|
|
|
|
/**
|
|
* @var bool Value indicating whether push is allowed.
|
|
*/
|
|
private $push;
|
|
|
|
/**
|
|
* Creates a new permission.
|
|
* @param bool $admin Value indicating whether administrator access is allowed.
|
|
* @param bool $pull Value indicating whether pull is allowed.
|
|
* @param bool $push Value indicating whether push is allowed.
|
|
*/
|
|
function __construct(bool $admin = false, bool $pull = false, bool $push = false) {
|
|
$this->setAdmin($admin)->setPull($pull)->setPush($push);
|
|
}
|
|
|
|
/**
|
|
* Creates a new user from the specified JSON map.
|
|
* @param object $map A JSON map representing a user.
|
|
* @return static The instance corresponding to the specified JSON map.
|
|
*/
|
|
static function fromJson(object $map): self {
|
|
return new static(
|
|
isset($map->admin) && is_bool($map->admin) ? $map->admin : false,
|
|
isset($map->pull) && is_bool($map->pull) ? $map->pull : false,
|
|
isset($map->push) && is_bool($map->push) ? $map->push : false
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Gets a value indicating whether administrator access is allowed.
|
|
* @return bool `true` if administrator access is allowed, otherwise `false`.
|
|
*/
|
|
function getAdmin(): bool {
|
|
return $this->admin;
|
|
}
|
|
|
|
/**
|
|
* Gets a value indicating whether pull is allowed.
|
|
* @return bool `true` if pull is allowed, otherwise `false`.
|
|
*/
|
|
function getPull(): bool {
|
|
return $this->pull;
|
|
}
|
|
|
|
/**
|
|
* Gets a value indicating whether push is allowed.
|
|
* @return bool `true` if push is allowed, otherwise `false`.
|
|
*/
|
|
function getPush(): bool {
|
|
return $this->push;
|
|
}
|
|
|
|
/**
|
|
* Converts this object to a map in JSON format.
|
|
* @return \stdClass The map in JSON format corresponding to this object.
|
|
*/
|
|
function jsonSerialize(): \stdClass {
|
|
return (object) [
|
|
'admin' => $this->getAdmin(),
|
|
'pull' => $this->getPull(),
|
|
'push' => $this->getPush()
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Sets a value indicating whether administrator access is allowed.
|
|
* @param bool $value `true` to allow administrator access, otherwise `false`.
|
|
* @return $this This instance.
|
|
*/
|
|
function setAdmin(bool $value): self {
|
|
$this->admin = $value;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Sets a value indicating whether pull is allowed.
|
|
* @param bool $value `true` to allow pull, otherwise `false`.
|
|
* @return $this This instance.
|
|
*/
|
|
function setPull(bool $value): self {
|
|
$this->pull = $value;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Sets a value indicating whether push is allowed.
|
|
* @param bool $value `true` to allow push, otherwise `false`.
|
|
* @return $this This instance.
|
|
*/
|
|
function setPush(bool $value): self {
|
|
$this->push = $value;
|
|
return $this;
|
|
}
|
|
}
|