diff --git a/src/Model/Branch.php b/src/Model/Branch.php new file mode 100644 index 0000000..a9688a1 --- /dev/null +++ b/src/Model/Branch.php @@ -0,0 +1,135 @@ +setGiteaClient($giteaClient); + $this->setApiRequester($apiRequester); + if (count($args) >= 1) { + $name = $args[0]; + if (!is_string($name)) { + $argumentType = gettype($name); + throw new InvalidArgumentException("The \"__construct()\" function requires the 4th parameter to be of the string type, but a \"$argumentType\" was passed in"); + } + $this->setName($name); + } else { + $numArgs = func_num_args(); + throw new InvalidArgumentException("The \"__construct()\" function requires 4 parameters but only $numArgs were passed in"); + } + } + + /** + * Creates a new branch from the specified JSON map. + * @param object $giteaClient The Gitea client that originally made the request for this object's data + * @param object $apiRequester The Api requester that created this object + * @param object $map A JSON map representing an branch. + * @return static The instance corresponding to the specified JSON map. + */ + static function fromJson(object $giteaClient, object $apiRequester, object $map): self { + return ( + new static( + $giteaClient, + $apiRequester, + isset($map->name) && is_string($map->name) ? $map->name : '' + ) + ) + ->setCommit(isset($map->commit) && is_object($map->commit) ? PayloadCommit::fromJson($giteaClient, $apiRequester, $map->commit) : null) + ->setProtected(isset($map->protected) && is_bool($map->protected) ? $map->protected : true) + ->setCanUserPush(isset($map->user_can_push) && is_bool($map->user_can_push) ? $map->user_can_push : false) + ->setUserCanMerge(isset($map->user_can_merge) && is_bool($map->user_can_merge) ? $map->user_can_merge : false); + } + + /** + * 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) [ + 'name' => $this->getName(), + 'commit' => ($commit = $this->getCommit()) ? $commit->jsonSerialize() : null, + 'protected' => $this->getProtected(), + 'user_can_push' => $this->getCanUserPush(), + 'user_can_merge' => $this->getUserCanMerge() + ]; + } + + public function getName(): string { + return $this->name; + } + + public function setName(string $name): self { + $this->name = $name; + return $this; + } + + public function getCommit(): ?PayloadCommit { + return $this->commit; + } + + public function setCommit(?PayloadCommit $object): self { + $this->commit = $object; + return $this; + } + + public function getProtected() { + return $this->protected; + } + + public function setProtected(bool $boolean): self { + $this->protected = $boolean; + return $this; + } + + public function getCanUserPush() { + return $this->canUserPush; + } + + public function setCanUserPush(bool $boolean): self { + $this->canUserPush = $boolean; + return $this; + } + + public function getUserCanMerge() { + return $this->userCanMerge; + } + + public function setUserCanMerge(bool $boolean): self { + $this->userCanMerge = $boolean; + return $this; + } + +} diff --git a/src/Model/Owner.php b/src/Model/Owner.php new file mode 100644 index 0000000..0aa3df3 --- /dev/null +++ b/src/Model/Owner.php @@ -0,0 +1,223 @@ +setGiteaClient($giteaClient); + $this->setApiRequester($apiRequester); + if (count($args) >= 2) { + $id = $args[0]; + $login = $args[1]; + if (!is_int($id)) { + $argumentType = gettype($id); + throw new InvalidArgumentException("The \"__construct()\" function requires the 3rd parameter to be of the integer type, but a \"$argumentType\" was passed in"); + } + if (!is_string($login)) { + $argumentType = gettype($login); + throw new InvalidArgumentException("The \"__construct()\" function requires the 4th parameter to be of the string type, but a \"$argumentType\" was passed in"); + } + $this->id = $id; + $this->setLogin($login); + } else { + $numArgs = func_num_args(); + throw new InvalidArgumentException("The \"__construct()\" function requires 4 parameters but only $numArgs were passed in"); + } + } + + /** + * Creates a new owner from the specified JSON map. + * @param object $giteaClient The Gitea client that originally made the request for this object's data + * @param object $apiRequester The Api requester that created this object + * @param object $map A JSON map representing a owner. + * @return static The instance corresponding to the specified JSON map. + */ + static function fromJson(object $giteaClient, object $apiRequester, object $map): self { + return ( + new static( + $giteaClient, + $apiRequester, + isset($map->id) && is_int($map->id) ? $map->id : -1, + isset($map->login) && is_string($map->login) ? $map->login : '' + ) + ) + ->setAvatarUrl(isset($map->avatar_url) && is_string($map->avatar_url) ? new Uri($map->avatar_url) : null) + ->setEmail(isset($map->email) && is_string($map->email) ? mb_strtolower($map->email) : '') + ->setFullName(isset($map->full_name) && is_string($map->full_name) ? $map->full_name : '') + ->setLanguage(isset($map->language) && is_string($map->language) ? $map->language : '') + ->setIsAdmin(isset($map->is_admin) && is_bool($map->is_admin) ? $map->is_admin : false) + ->setUsername(isset($map->username) && is_string($map->username) ? $map->username : ''); + } + + /** + * 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) [ + 'id' => $this->getId(), + 'login' => $this->getLogin(), + 'full_name' => $this->getFullName(), + 'email' => $this->getEmail(), + 'avatar_url' => ($url = $this->getAvatarUrl()) ? (string) $url : null, + 'language' => $this->getLanguage(), + 'is_admin' => $this->getIsAdmin(), + 'username' => $this->getUsername() + ]; + } + + /** + * Gets the owner identifier. + * @return int The owner identifier. + */ + function getId(): int { + return $this->id; + } + + /** + * Gets the name of the Gitea account. + * @return string The name of the Gitea account. + */ + function getLogin(): string { + return $this->login; + } + + /** + * 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; + } + + /** + * Gets the full name. + * @return string The full name. + */ + function getFullName(): string { + return $this->fullName; + } + + /** + * 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; + } + + /** + * Gets the mail address. + * @return string The mail address. + */ + function getEmail(): string { + return $this->email; + } + + /** + * 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; + } + + /** + * Gets the URL of the avatar image. + * @return UriInterface|null The URL of the avatar image. + */ + function getAvatarUrl(): ?UriInterface { + return $this->avatarUrl; + } + + /** + * Sets the URL of the avatar image. + * @param UriInterface|null $value The new avatar URL. + * @return $this This instance. + */ + function setAvatarUrl(?UriInterface $value): self { + $this->avatarUrl = $value; + return $this; + } + + /** + * Gets the owner locale. + * @return string The owner locale. + */ + function getLanguage(): string { + return $this->language; + } + + /** + * Sets the owner locale. + * @param string $value The new owner locale. + * @return $this This instance. + */ + function setLanguage(string $value): self { + $this->language = $value; + return $this; + } + + public function getIsAdmin(): boolean { + return $this->isAdmin; + } + + public function setIsAdmin($boolean): self { + $this->isAdmin = $boolean; + return $this; + } + + public function getUsername(): string { + return $this->username; + } + + public function setUsername($string): self { + $this->username = $string; + return $this; + } + +} diff --git a/src/Model/Tag.php b/src/Model/Tag.php new file mode 100644 index 0000000..5155ab9 --- /dev/null +++ b/src/Model/Tag.php @@ -0,0 +1,157 @@ + "", + "url" => null, + ]; + + /** + * Creates a new tag + * @param object $giteaClient The Gitea client that originally made the request for this object's data + * @param object $apiRequester The Api requester that created this object + * @param int $id The tag identifier + * @param string $name The tag name + */ + function __construct(object $giteaClient, object $apiRequester, ...$args) { + $this->setGiteaClient($giteaClient); + $this->setApiRequester($apiRequester); + if (count($args) >= 2) { + $id = $args[0]; + $name = $args[1]; + if (!is_int($id)) { + $argumentType = gettype($id); + throw new InvalidArgumentException("The \"__construct()\" function requires the 3rd parameter to be of the integer type, but a \"$argumentType\" was passed in"); + } + if (!is_string($name)) { + $argumentType = gettype($name); + throw new InvalidArgumentException("The \"__construct()\" function requires the 4th parameter to be of the string type, but a \"$argumentType\" was passed in"); + } + $this->id = $id; + $this->setName($name); + } else { + $numArgs = func_num_args(); + throw new InvalidArgumentException("The \"__construct()\" function requires 4 parameters but only $numArgs were passed in"); + } + } + + /** + * Creates a new tag from the specified JSON map. + * @param object $giteaClient The Gitea client that originally made the request for this object's data + * @param object $apiRequester The Api requester that created this object + * @param object $map A JSON map representing an tag. + * @return static The instance corresponding to the specified JSON map. + */ + static function fromJson(object $giteaClient, object $apiRequester, object $map): self { + $newTag = new static( + $giteaClient, + $apiRequester, + isset($map->id) && is_int($map->id) ? $map->id : -1, + isset($map->name) && is_string($map->name) ? $map->name : '' + ); + $newTag->setTarballURL(isset($map->tarball_url) && is_string($map->tarball_url) ? new Uri($map->tarball_url) : null); + $newTag->setZipballURL(isset($map->zipball_url) && is_string($map->zipball_url) ? new Uri($map->zipball_url) : null); + if (isset($map->commit)) { + $newTag->setCommitSha(isset($map->commit->sha) && is_string($map->commit->sha) ? $map->commit->sha : ""); + $newTag->setCommitUrl(isset($map->commit->url) && is_string($map->commit->url) ? new Uri($map->commit->url) : null); + } + return $newTag; + } + + /** + * 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) [ + 'id' => $this->getId(), + 'name' => $this->getName(), + 'tarball_url' => ($url = $this->getTarballURL()) ? (string) $url : null, + 'zipball_url' => ($url = $this->getZipballURL()) ? (string) $url : null, + 'commit' => [ + "sha" => $this->getCommitSha(), + "url" => ($url = $this->getCommitUrl()) ? (string) $url : null + ], + ]; + } + + /** + * Gets the tag identifier. + * @return int The tag identifier. + */ + function getId(): int { + return $this->id; + } + + public function getName(): string { + return $this->name; + } + + public function setName($name): self { + $this->name = $name; + return $this; + } + + public function getTarballURL(): ?UriInterface { + return $this->tarballURL; + } + + public function setTarballURL(?UriInterface $url): self { + $this->tarballURL = $url; + return $this; + } + + public function getZipballURL(): ?UriInterface { + return $this->zipballURL; + } + + public function setZipballURL(?UriInterface $url): self { + $this->zipballURL = $url; + return $this; + } + + public function getCommitSha(): string { + $commit = $this->commit; + return $commit["sha"]; + } + + public function setCommitSha(string $string): self { + $this->commit["sha"] = $string; + return $this; + } + + public function getCommitUrl(): ?uri { + $commit = $this->commit; + return $commit["url"]; + } + + public function setCommitUrl(?uri $url): self { + $this->commit["url"] = $url; + return $this; + } + +}