mirror of
https://github.com/sitelease/sugar-cube-client.git
synced 2025-10-31 20:12:29 +01:00
Porting the models to JsonSerializable interface
This commit is contained in:
@ -7,10 +7,8 @@ use Psr\Http\Message\{UriInterface};
|
||||
|
||||
/**
|
||||
* Represents a commit.
|
||||
* @property \DateTime|null $timestamp The commit date.
|
||||
* @property UriInterface|null $url The URL to the commit's history.
|
||||
*/
|
||||
class PayloadCommit {
|
||||
class PayloadCommit implements \JsonSerializable {
|
||||
|
||||
/**
|
||||
* @var PayloadUser|null The person who authored the commit.
|
||||
@ -64,22 +62,6 @@ class PayloadCommit {
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of fields that should be returned by default.
|
||||
* @return array The list of field names or field definitions.
|
||||
*/
|
||||
function fields(): array {
|
||||
return [
|
||||
'author',
|
||||
'committer',
|
||||
'id',
|
||||
'message',
|
||||
'timestamp' => function(PayloadCommit $model) { return ($date = $model->getTimestamp()) ? $date->format('c') : null; },
|
||||
'url' => function(self $model) { return ($url = $model->getUrl()) ? (string) $url : null; },
|
||||
'verification'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the commit date.
|
||||
* @return \DateTime|null The commit date.
|
||||
@ -96,6 +78,22 @@ class PayloadCommit {
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) [
|
||||
'author',
|
||||
'committer',
|
||||
'id',
|
||||
'message',
|
||||
'timestamp' => ($date = $this->getTimestamp()) ? $date->format('c') : null,
|
||||
'url' => ($url = $this->getUrl()) ? (string) $url : null,
|
||||
'verification'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the commit date.
|
||||
* @param \DateTime|string|null $value The new commit date.
|
||||
|
||||
@ -5,7 +5,7 @@ namespace Gitea\Models;
|
||||
/**
|
||||
* Represents the GPG verification of a commit.
|
||||
*/
|
||||
class PayloadCommitVerification {
|
||||
class PayloadCommitVerification implements \JsonSerializable {
|
||||
|
||||
/**
|
||||
* @var bool Value indicating whether the verification has succeeded.
|
||||
@ -42,11 +42,11 @@ class PayloadCommitVerification {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of fields that should be returned by default.
|
||||
* @return array The list of field names or field definitions.
|
||||
* Converts this object to a map in JSON format.
|
||||
* @return \stdClass The map in JSON format corresponding to this object.
|
||||
*/
|
||||
function fields(): array {
|
||||
return [
|
||||
function jsonSerialize(): \stdClass {
|
||||
return (object) [
|
||||
'payload',
|
||||
'reason',
|
||||
'signature',
|
||||
|
||||
@ -7,14 +7,8 @@ use Psr\Http\Message\{UriInterface};
|
||||
|
||||
/**
|
||||
* Represents a repository.
|
||||
* @property UriInterface|null $cloneUrl The HTTP-based URL for cloning this repository.
|
||||
* @property \DateTime|null $createdAt The date the repository was created.
|
||||
* @property UriInterface|null $htmlUrl The Gitea URL of this repository.
|
||||
* @property UriInterface|null $sshUrl The SSH-based URL for cloning this repository.
|
||||
* @property \DateTime|null $updatedAt The date the repository was updated.
|
||||
* @property UriInterface|null $website The URL of the repository website.
|
||||
*/
|
||||
class Repository {
|
||||
class Repository implements \JsonSerializable {
|
||||
|
||||
/**
|
||||
* @var string The name of the default branch.
|
||||
@ -164,38 +158,6 @@ class Repository {
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of fields that should be returned by default.
|
||||
* @return array The list of field names or field definitions.
|
||||
*/
|
||||
function fields(): array {
|
||||
return [
|
||||
'clone_url' => function(self $model) { return ($url = $model->getCloneUrl()) ? (string) $url : null; },
|
||||
'created_at' => function(Repository $model) { return ($date = $model->getCreatedAt()) ? $date->format('c') : null; },
|
||||
'default_branch' => 'defaultBranch',
|
||||
'description',
|
||||
'empty' => 'isEmpty',
|
||||
'fork' => 'isFork',
|
||||
'forks_count' => 'forksCount',
|
||||
'full_name' => 'fullName',
|
||||
'html_url' => function(self $model) { return ($url = $model->getHtmlUrl()) ? (string) $url : null; },
|
||||
'id',
|
||||
'mirror' => 'isMirror',
|
||||
'name',
|
||||
'open_issues_count' => 'openIssuesCount',
|
||||
'owner',
|
||||
'parent',
|
||||
'permissions',
|
||||
'private' => 'isPrivate',
|
||||
'size',
|
||||
'ssh_url' => function(self $model) { return ($url = $model->getSshUrl()) ? (string) $url : null; },
|
||||
'stars_count' => 'starsCount',
|
||||
'updated_at' => function(Repository $model) { return ($date = $model->getUpdatedAt()) ? $date->format('c') : null; },
|
||||
'watchers_count' => 'watchersCount',
|
||||
'website' => function(self $model) { return ($url = $model->getWebsite()) ? (string) $url : null; },
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the HTTP-based URL for cloning this repository.
|
||||
* @return UriInterface|null The HTTP-based URL for cloning this repository.
|
||||
@ -244,6 +206,38 @@ class Repository {
|
||||
return $this->website;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) [
|
||||
'clone_url' => ($url = $this->getCloneUrl()) ? (string) $url : null,
|
||||
'created_at' => ($date = $this->getCreatedAt()) ? $date->format('c') : null,
|
||||
'default_branch' => 'defaultBranch',
|
||||
'description',
|
||||
'empty' => 'isEmpty',
|
||||
'fork' => 'isFork',
|
||||
'forks_count' => 'forksCount',
|
||||
'full_name' => 'fullName',
|
||||
'html_url' => ($url = $this->getHtmlUrl()) ? (string) $url : null,
|
||||
'id',
|
||||
'mirror' => 'isMirror',
|
||||
'name',
|
||||
'open_issues_count' => 'openIssuesCount',
|
||||
'owner',
|
||||
'parent',
|
||||
'permissions',
|
||||
'private' => 'isPrivate',
|
||||
'size',
|
||||
'ssh_url' => ($url = $this->getSshUrl()) ? (string) $url : null,
|
||||
'stars_count' => 'starsCount',
|
||||
'updated_at' => ($date = $this->getUpdatedAt()) ? $date->format('c') : null,
|
||||
'watchers_count' => 'watchersCount',
|
||||
'website' => ($url = $this->getWebsite()) ? (string) $url : null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the HTTP-based URL for cloning this repository.
|
||||
* @param UriInterface|string|null $value The new URL for cloning this repository.
|
||||
|
||||
@ -7,40 +7,39 @@ use Psr\Http\Message\{UriInterface};
|
||||
|
||||
/**
|
||||
* Represents a Gitea user.
|
||||
* @property UriInterface|null $avatarUrl The URL of the avatar image.
|
||||
*/
|
||||
class User {
|
||||
|
||||
/**
|
||||
* @var string The mail address.
|
||||
*/
|
||||
public $email = '';
|
||||
|
||||
/**
|
||||
* @var string The full name.
|
||||
*/
|
||||
public $fullName = '';
|
||||
|
||||
/**
|
||||
* @var int The user identifier.
|
||||
*/
|
||||
public $id = -1;
|
||||
|
||||
/**
|
||||
* @var string The user locale.
|
||||
*/
|
||||
public $language = '';
|
||||
|
||||
/**
|
||||
* @var string The name of the Gitea account.
|
||||
*/
|
||||
public $login = '';
|
||||
class User implements \JsonSerializable {
|
||||
|
||||
/**
|
||||
* @var UriInterface|null The URL to the user's avatar.
|
||||
*/
|
||||
private $avatarUrl;
|
||||
|
||||
/**
|
||||
* @var string The mail address.
|
||||
*/
|
||||
private $email = '';
|
||||
|
||||
/**
|
||||
* @var string The full name.
|
||||
*/
|
||||
private $fullName = '';
|
||||
|
||||
/**
|
||||
* @var int The user identifier.
|
||||
*/
|
||||
private $id = -1;
|
||||
|
||||
/**
|
||||
* @var string The user locale.
|
||||
*/
|
||||
private $language = '';
|
||||
|
||||
/**
|
||||
* @var string The name of the Gitea account.
|
||||
*/
|
||||
private $login = '';
|
||||
|
||||
/**
|
||||
* Creates a new user from the specified JSON map.
|
||||
* @param object $map A JSON map representing a user.
|
||||
@ -57,21 +56,6 @@ class User {
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of fields that should be returned by default.
|
||||
* @return array The list of field names or field definitions.
|
||||
*/
|
||||
function fields(): array {
|
||||
return [
|
||||
'avatar_url' => function(self $model) { return ($url = $model->getAvatarUrl()) ? (string) $url : null; },
|
||||
'email',
|
||||
'full_name' => 'fullName',
|
||||
'id',
|
||||
'language',
|
||||
'login'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the URL of the avatar image.
|
||||
* @return UriInterface|null The URL of the avatar image.
|
||||
@ -80,6 +64,61 @@ class User {
|
||||
return $this->avatarUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the mail address.
|
||||
* @return string The mail address.
|
||||
*/
|
||||
function getEmail(): string {
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the full name.
|
||||
* @return string The full name.
|
||||
*/
|
||||
function getFullName(): string {
|
||||
return $this->fullName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the user identifier.
|
||||
* @return int The user identifier.
|
||||
*/
|
||||
function getId(): int {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the user locale.
|
||||
* @return string The user locale.
|
||||
*/
|
||||
function getLanguage(): string {
|
||||
return $this->language;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the Gitea account.
|
||||
* @return string The name of the Gitea account.
|
||||
*/
|
||||
function getLogin(): string {
|
||||
return $this->login;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) [
|
||||
'avatar_url' => ($url = $this->getAvatarUrl()) ? (string) $url : null,
|
||||
'email' => $this->getEmail(),
|
||||
'full_name' => $this->getFullName(),
|
||||
'id' => $this->getId(),
|
||||
'language' => $this->getLanguage(),
|
||||
'login' => $this->getLogin()
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the URL of the avatar image.
|
||||
* @param UriInterface|string|null $value The new avatar URL.
|
||||
@ -89,4 +128,54 @@ class User {
|
||||
$this->avatarUrl = is_string($value) ? new Uri($value) : $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the mail address.
|
||||
* @param string $value The new mail address.
|
||||
* @return $this This instance.
|
||||
*/
|
||||
function setEmail(string $value): self {
|
||||
$this->email = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the full name.
|
||||
* @param string $value The new full name.
|
||||
* @return $this This instance.
|
||||
*/
|
||||
function setFullName(string $value): self {
|
||||
$this->fullName = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the user identifier.
|
||||
* @param int $value The new user identifier.
|
||||
* @return $this This instance.
|
||||
*/
|
||||
function setId(int $value): self {
|
||||
$this->id = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the user locale.
|
||||
* @param string $value The new user locale.
|
||||
* @return $this This instance.
|
||||
*/
|
||||
function setLanguage(string $value): self {
|
||||
$this->language = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the Gitea account.
|
||||
* @param string $value The new Gitea account.
|
||||
* @return $this This instance.
|
||||
*/
|
||||
function setLogin(string $value): self {
|
||||
$this->login = $value;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user