Skip to content

Commit

Permalink
Post: ImageStorage should be lazy-loaded.
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarasek authored Oct 27, 2021
1 parent 1555985 commit 3254439
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class Post
{
private ImageStorage $imageStorage;
private ?ImageStorage $imageStorage = null;

private string $title;

Expand All @@ -30,13 +30,11 @@ public function __construct(
string $description,
string $link,
\DateTimeImmutable $date,
ImageStorage $imageStorage
) {
$this->title = $title;
$this->description = $description;
$this->link = $link;
$this->date = $date;
$this->imageStorage = $imageStorage;
}


Expand Down Expand Up @@ -106,6 +104,8 @@ public function setCategories(array $categories): self

public function getAbsoluteInternalUrl(): ?string
{
assert($this->imageStorage !== null);

return $this->mainImageUrl !== null
? $this->imageStorage->getAbsoluteInternalUrl($this->mainImageUrl)
: null;
Expand All @@ -114,6 +114,8 @@ public function getAbsoluteInternalUrl(): ?string

public function getRelativeInternalUrl(): ?string
{
assert($this->imageStorage !== null);

return $this->mainImageUrl !== null
? $this->imageStorage->getRelativeInternalUrl($this->mainImageUrl)
: null;
Expand Down

0 comments on commit 3254439

Please sign in to comment.