From 79f0d489ebb1e875e7a8870a4439daa127893eec Mon Sep 17 00:00:00 2001 From: Julian Saupe Date: Thu, 10 Oct 2024 20:03:14 +0200 Subject: [PATCH] Add property method as defined in RFC-5545. --- src/Domain/Entity/Event.php | 21 +++++++++++++++++++++ src/Domain/Enum/Method.php | 19 +++++++++++++++++++ src/Presentation/Factory/EventFactory.php | 18 ++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 src/Domain/Enum/Method.php diff --git a/src/Domain/Entity/Event.php b/src/Domain/Entity/Event.php index fce585b1..38ba087c 100644 --- a/src/Domain/Entity/Event.php +++ b/src/Domain/Entity/Event.php @@ -12,6 +12,7 @@ namespace Eluceo\iCal\Domain\Entity; use Eluceo\iCal\Domain\Enum\EventStatus; +use Eluceo\iCal\Domain\Enum\Method; use Eluceo\iCal\Domain\ValueObject\Alarm; use Eluceo\iCal\Domain\ValueObject\Attachment; use Eluceo\iCal\Domain\ValueObject\Category; @@ -34,6 +35,7 @@ class Event private ?Organizer $organizer = null; private ?Timestamp $lastModified = null; private ?EventStatus $status = null; + private ?Method $method = null; /** * @var array @@ -347,4 +349,23 @@ public function unsetStatus(): self return $this; } + + public function getMethod(): Method + { + assert($this->method !== null); + + return $this->method; + } + + public function hasMethod(): bool + { + return $this->method !== null; + } + + public function setMethod(Method $method): self + { + $this->method = $method; + + return $this; + } } diff --git a/src/Domain/Enum/Method.php b/src/Domain/Enum/Method.php new file mode 100644 index 00000000..30a1d23d --- /dev/null +++ b/src/Domain/Enum/Method.php @@ -0,0 +1,19 @@ +getEventStatusTextValue($event->getStatus())); } + if ($event->hasMethod()) { + yield new Property('METHOD', $this->getMethodTextValue($event->getMethod())); + } + foreach ($event->getAttachments() as $attachment) { yield from $this->getAttachmentProperties($attachment); } @@ -278,4 +283,17 @@ private function getEventStatusTextValue(EventStatus $status): TextValue throw new UnexpectedValueException(sprintf('The enum %s resulted into an unknown status type value that is not yet implemented.', EventStatus::class)); } + + private function getMethodTextValue(Method $method): TextValue + { + if ($method === Method::PUBLISH()) { + return new TextValue('PUBLISH'); + } + + if ($method === Method::REQUEST()) { + return new TextValue('REQUEST'); + } + + throw new UnexpectedValueException(sprintf('The enum %s resulted into an unknown method type value that is not yet implemented.', Method::class)); + } }