mirror of
https://github.com/sitelease/sugar-cube-client.git
synced 2025-10-31 20:12:29 +01:00
Replacing public properties by getters and setters
This commit is contained in:
@ -5,22 +5,32 @@ namespace Gitea\Models;
|
||||
/**
|
||||
* Represents a set of permissions.
|
||||
*/
|
||||
class Permission {
|
||||
class Permission implements \JsonSerializable {
|
||||
|
||||
/**
|
||||
* @var bool Value indicating whether administrator access is allowed.
|
||||
*/
|
||||
public $admin = false;
|
||||
private $admin;
|
||||
|
||||
/**
|
||||
* @var bool Value indicating whether pull is allowed.
|
||||
*/
|
||||
public $pull = false;
|
||||
private $pull;
|
||||
|
||||
/**
|
||||
* @var bool Value indicating whether push is allowed.
|
||||
*/
|
||||
public $push = false;
|
||||
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.
|
||||
@ -28,10 +38,76 @@ class Permission {
|
||||
* @return static The instance corresponding to the specified JSON map.
|
||||
*/
|
||||
static function fromJson(object $map): self {
|
||||
return new static([
|
||||
'admin' => isset($map->admin) && is_bool($map->admin) ? $map->admin : false,
|
||||
'pull' => isset($map->pull) && is_bool($map->pull) ? $map->pull : false,
|
||||
'push' => isset($map->push) && is_bool($map->push) ? $map->push : false
|
||||
]);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user