123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <?php
- declare(strict_types=1);
- namespace OCP\Http\WellKnown;
- use OCP\AppFramework\Http\JSONResponse;
- use OCP\AppFramework\Http\Response;
- use function array_filter;
- final class JrdResponse implements IResponse {
-
- private $subject;
-
- private $expires;
-
- private $aliases = [];
-
- private $properties = [];
-
- private $links;
-
- public function __construct(string $subject) {
- $this->subject = $subject;
- }
-
- public function setExpires(string $expires): self {
- $this->expires = $expires;
- return $this;
- }
-
- public function addAlias(string $alias): self {
- $this->aliases[] = $alias;
- return $this;
- }
-
- public function addProperty(string $property, ?string $value): self {
- $this->properties[$property] = $value;
- return $this;
- }
-
- public function addLink(string $rel,
- ?string $type,
- ?string $href,
- ?array $titles = [],
- ?array $properties = []): self {
- $this->links[] = array_filter([
- 'rel' => $rel,
- 'type' => $type,
- 'href' => $href,
- 'titles' => $titles,
- 'properties' => $properties,
- ]);
- return $this;
- }
-
- public function toHttpResponse(): Response {
- return new JSONResponse(array_filter([
- 'subject' => $this->subject,
- 'expires' => $this->expires,
- 'aliases' => $this->aliases,
- 'properties' => $this->properties,
- 'links' => $this->links,
- ]));
- }
-
- public function isEmpty(): bool {
- return $this->expires === null
- && empty($this->aliases)
- && empty($this->properties)
- && empty($this->links);
- }
- }
|