repod/lib/Core/EpisodeAction/EpisodeActionExtraData.php
Michel Roux 2d6f2cb5e7
All checks were successful
repod / xml (push) Successful in 15s
repod / php (push) Successful in 52s
repod / nodejs (push) Successful in 1m47s
repod / release (push) Has been skipped
fix: duration wrongly displayed
2024-01-16 19:46:02 +01:00

134 lines
2.8 KiB
PHP

<?php
declare(strict_types=1);
namespace OCA\RePod\Core\EpisodeAction;
use OCA\GPodderSync\Core\EpisodeAction\EpisodeAction;
/**
* Base: https://github.com/pbek/nextcloud-nextpod/blob/main/lib/Core/EpisodeAction/EpisodeActionExtraData.php.
* Specs: https://github.com/Podcast-Standards-Project/PSP-1-Podcast-RSS-Specification/blob/main/README.md#required-item-elements.
*
* @psalm-import-type EpisodeActionType from EpisodeAction
*
* @psalm-type EpisodeActionExtraDataType = array{
* title: string,
* url: ?string,
* name: string,
* link: ?string,
* image: ?string,
* description: ?string,
* fetchedAtUnix: int,
* guid: string,
* type: ?string,
* size: ?int,
* pubDate: ?\DateTime,
* duration: ?string,
* action: ?EpisodeActionType
* }
*/
class EpisodeActionExtraData implements \JsonSerializable
{
public function __construct(
private string $title,
private ?string $url,
private string $name,
private ?string $link,
private ?string $image,
private ?string $description,
private int $fetchedAtUnix,
private string $guid,
private ?string $type,
private ?int $size,
private ?\DateTime $pubDate,
private ?string $duration,
private ?EpisodeAction $action
) {}
public function __toString(): string {
return $this->url ?? '/no episodeUrl/';
}
public function getTitle(): string {
return $this->title;
}
public function getUrl(): ?string {
return $this->url;
}
public function getName(): string {
return $this->name;
}
public function getLink(): ?string {
return $this->link;
}
public function getImage(): ?string {
return $this->image;
}
public function getDescription(): ?string {
return $this->description;
}
public function getFetchedAtUnix(): int {
return $this->fetchedAtUnix;
}
public function getGuid(): string {
return $this->guid;
}
public function getType(): ?string {
return $this->type;
}
public function getSize(): ?int {
return $this->size;
}
public function getPubDate(): ?\DateTime {
return $this->pubDate;
}
public function getDuration(): ?string {
return $this->duration;
}
public function getAction(): ?EpisodeAction {
return $this->action;
}
/**
* @return EpisodeActionExtraDataType
*/
public function toArray(): array {
return
[
'title' => $this->title,
'url' => $this->url,
'name' => $this->name,
'link' => $this->link,
'image' => $this->image,
'description' => $this->description,
'fetchedAtUnix' => $this->fetchedAtUnix,
'guid' => $this->guid,
'type' => $this->type,
'size' => $this->size,
'pubDate' => $this->pubDate,
'duration' => $this->duration,
'action' => $this->action ? $this->action->toArray() : null,
];
}
/**
* @return EpisodeActionExtraDataType
*/
public function jsonSerialize(): mixed {
return $this->toArray();
}
}