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.
|
||||
|
||||
Reference in New Issue
Block a user