-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use value objects for slides, not Row
- Loading branch information
Showing
13 changed files
with
614 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
site/app/Talks/Exceptions/TalkSlideDoesNotExistException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace MichalSpacekCz\Talks\Exceptions; | ||
|
||
use Throwable; | ||
|
||
class TalkSlideDoesNotExistException extends TalkException | ||
{ | ||
|
||
public function __construct(int $talkId, int $number, ?Throwable $previous = null) | ||
{ | ||
parent::__construct("Talk id $talkId doesn't have a slide number $number", previous: $previous); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace MichalSpacekCz\Talks\Slides; | ||
|
||
use Nette\Utils\Html; | ||
|
||
class TalkSlide | ||
{ | ||
|
||
public function __construct( | ||
private readonly int $id, | ||
private readonly string $alias, | ||
private readonly int $number, | ||
private readonly ?string $filename, | ||
private readonly ?string $filenameAlternative, | ||
private readonly ?int $filenamesTalkId, | ||
private readonly string $title, | ||
private readonly Html $speakerNotes, | ||
private readonly string $speakerNotesTexy, | ||
private readonly ?string $image, | ||
private readonly ?string $imageAlternative, | ||
private readonly ?string $imageAlternativeType, | ||
) { | ||
} | ||
|
||
|
||
public function getId(): int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
|
||
public function getAlias(): string | ||
{ | ||
return $this->alias; | ||
} | ||
|
||
|
||
public function getNumber(): int | ||
{ | ||
return $this->number; | ||
} | ||
|
||
|
||
public function getFilename(): ?string | ||
{ | ||
return $this->filename; | ||
} | ||
|
||
|
||
public function getFilenameAlternative(): ?string | ||
{ | ||
return $this->filenameAlternative; | ||
} | ||
|
||
|
||
public function getFilenamesTalkId(): ?int | ||
{ | ||
return $this->filenamesTalkId; | ||
} | ||
|
||
|
||
public function getTitle(): string | ||
{ | ||
return $this->title; | ||
} | ||
|
||
|
||
public function getSpeakerNotes(): Html | ||
{ | ||
return $this->speakerNotes; | ||
} | ||
|
||
|
||
public function getSpeakerNotesTexy(): string | ||
{ | ||
return $this->speakerNotesTexy; | ||
} | ||
|
||
|
||
public function getImage(): ?string | ||
{ | ||
return $this->image; | ||
} | ||
|
||
|
||
public function getImageAlternative(): ?string | ||
{ | ||
return $this->imageAlternative; | ||
} | ||
|
||
|
||
public function getImageAlternativeType(): ?string | ||
{ | ||
return $this->imageAlternativeType; | ||
} | ||
|
||
|
||
/** | ||
* @return list<string> | ||
*/ | ||
public function getAllFilenames(): array | ||
{ | ||
$filenames = []; | ||
if ($this->filename) { | ||
$filenames[] = $this->filename; | ||
} | ||
if ($this->filenameAlternative) { | ||
$filenames[] = $this->filenameAlternative; | ||
} | ||
return $filenames; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace MichalSpacekCz\Talks\Slides; | ||
|
||
use ArrayIterator; | ||
use Countable; | ||
use IteratorAggregate; | ||
use MichalSpacekCz\Talks\Exceptions\TalkSlideDoesNotExistException; | ||
|
||
/** | ||
* @implements IteratorAggregate<int, TalkSlide> | ||
*/ | ||
class TalkSlideCollection implements IteratorAggregate, Countable | ||
{ | ||
|
||
/** @var array<int, TalkSlide> slide number => slide */ | ||
private array $slides = []; | ||
|
||
|
||
public function __construct( | ||
private readonly int $talkId, | ||
) { | ||
} | ||
|
||
|
||
public function add(TalkSlide $slide): void | ||
{ | ||
$this->slides[$slide->getNumber()] = $slide; | ||
} | ||
|
||
|
||
/** | ||
* @throws TalkSlideDoesNotExistException | ||
*/ | ||
public function getByNumber(int $number): TalkSlide | ||
{ | ||
if (!isset($this->slides[$number])) { | ||
throw new TalkSlideDoesNotExistException($this->talkId, $number); | ||
} | ||
return $this->slides[$number]; | ||
} | ||
|
||
|
||
/** | ||
* @return ArrayIterator<int, TalkSlide> | ||
*/ | ||
public function getIterator(): ArrayIterator | ||
{ | ||
return new ArrayIterator($this->slides); | ||
} | ||
|
||
|
||
public function count(): int | ||
{ | ||
return count($this->slides); | ||
} | ||
|
||
} |
Oops, something went wrong.