mirror of https://github.com/FriendsOfTYPO3/tea.git synced 2025-03-14 21:43:49 +01:00
tea/Classes/Domain/Model/Tea.php
Oliver Klee fb5066a2d7
[BUGFIX] Improve type safety for lazy-loaded associations ()
`_loadRealInstance` will return `null` if the target of the
association does not exist (anymore). We need to handle that case
in a clean way.

Also use a dedicated folder for the fixture to make the fixture
easier to find, and to discourage reuse of fixtures.
2025-02-04 19:06:44 +01:00

82 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace TTN\Tea\Domain\Model;
use TYPO3\CMS\Extbase\Annotation as Extbase;
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
use TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy;
/**
* This class represents a tea (flavor), e.g., "Earl Grey".
*/
class Tea extends AbstractEntity
{
#[Extbase\Validate(['validator' => 'StringLength', 'options' => ['maximum' => 255]])]
#[Extbase\Validate(['validator' => 'NotEmpty'])]
protected string $title = '';
#[Extbase\Validate(['validator' => 'StringLength', 'options' => ['maximum' => 2000]])]
protected string $description = '';
#[Extbase\ORM\Lazy]
protected FileReference|LazyLoadingProxy|null $image = null;
/**
* @var int<0, max>
*/
protected int $ownerUid = 0;
public function getTitle(): string
{
return $this->title;
}
public function setTitle(string $title): void
{
$this->title = $title;
}
public function getDescription(): string
{
return $this->description;
}
public function setDescription(string $description): void
{
$this->description = $description;
}
public function getImage(): ?FileReference
{
if ($this->image instanceof LazyLoadingProxy) {
$image = $this->image->_loadRealInstance();
$this->image = ($image instanceof FileReference) ? $image : null;
}
return $this->image;
}
public function setImage(FileReference $image): void
{
$this->image = $image;
}
/**
* @return int<0, max>
*/
public function getOwnerUid(): int
{
return $this->ownerUid;
}
/**
* @param int<0, max> $ownerUid
*/
public function setOwnerUid(int $ownerUid): void
{
$this->ownerUid = $ownerUid;
}
}