Replacing public properties by getters and setters

This commit is contained in:
Cédric Belin
2018-11-08 18:00:19 +01:00
parent ded2f54c96
commit c0653faeb7
9 changed files with 423 additions and 97 deletions

View File

@ -5,22 +5,22 @@ namespace Gitea\Models;
/**
* Represents the author or committer of a commit.
*/
class PayloadUser {
class PayloadUser implements \JsonSerializable {
/**
* @var string The mail address.
*/
public $email = '';
private $email = '';
/**
* @var string The full name.
*/
public $name = '';
private $name = '';
/**
* @var string The name of the Gitea account.
*/
public $username = '';
private $username = '';
/**
* Creates a new user from the specified JSON map.
@ -34,4 +34,21 @@ class PayloadUser {
'username' => 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) [
'after' => $this->getAfter(),
'before' => $this->getBefore(),
'compare_url' => ($url = $this->getCompareUrl()) ? (string) $url : null,
'commits' => array_map(function(PayloadCommit $commit) { return $commit->jsonSerialize(); }, $this->getCommits()->getArrayCopy()),
'pusher',
'ref' => $this->getRef(),
'repository',
'sender'
];
}
}