Files
newspage/classes/Application/Models/Article.php
2024-11-07 21:34:32 +01:00

109 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace Application\Models;
use Exception;
use JMS\Serializer\Annotation\SerializedName;
use JMS\Serializer\Annotation\Type;
class Article
{
use Meta;
#[SerializedName('authors')]
#[Type('array<' . Author::class . '>')]
protected ?array $authors = null;
#[SerializedName('headline')]
#[Type('string')]
protected ?string $headline = null;
#[SerializedName('excerpt')]
#[Type('string')]
protected ?string $excerpt = null;
#[SerializedName('image')]
#[Type(Image::class)]
protected ?Image $image = null;
#[SerializedName('text')]
#[Type('string')]
protected ?string $text = null;
/**
* Return the title / headline.
*
* @return string|null
*/
public function getTitle(): string|null
{
return $this->headline;
}
/**
* Return the text / article body text.
*
* @return string|null
*/
public function getText(): string|null
{
return $this->text;
}
/**
* Get the excerpt / teaser text.
*
* @return string|null
*/
public function getExcerpt(): string|null
{
return $this->excerpt;
}
public function getImage(): Image|null
{
return $this->image;
}
public function getTeaserData(): array
{
return [
'headline' => $this->getHeadline(),
'kicker' => $this->getKicker(),
'excerpt' => $this->getExcerpt(),
'teaserImage' => $this->getTeaserImage(),
'url' => $this->getUrl(),
];
}
private function getIdentifier(): string
{
return $this->metaId;
}
private function getHeadline(): ?string
{
return $this->headline;
}
private function getKicker(): ?string
{
return $this->excerpt;
}
/**
* @throws Exception
*/
private function getTeaserImage(): array
{
return $this->image->getTeaserData();
}
public function getUrl(): string
{
return '/article/test_article-' . $this->getIdentifier();
}
}