Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add property 'method' as defined in RFC-5545. #641

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/Domain/Entity/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,6 +35,7 @@ class Event
private ?Organizer $organizer = null;
private ?Timestamp $lastModified = null;
private ?EventStatus $status = null;
private ?Method $method = null;

/**
* @var array<Attendee>
Expand Down Expand Up @@ -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;
}
}
19 changes: 19 additions & 0 deletions src/Domain/Enum/Method.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Eluceo\iCal\Domain\Enum;

final class Method
{
private static ?self $request = null;
private static ?self $publish = null;

public static function REQUEST(): self
{
return self::$request ??= new self();
}

public static function PUBLISH(): self
{
return self::$publish ??= new self();
}
}
18 changes: 18 additions & 0 deletions src/Presentation/Factory/EventFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Eluceo\iCal\Domain\Collection\Events;
use Eluceo\iCal\Domain\Entity\Event;
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\MultiDay;
Expand Down Expand Up @@ -125,6 +126,10 @@ protected function getProperties(Event $event): Generator
yield new Property('STATUS', $this->getEventStatusTextValue($event->getStatus()));
}

if ($event->hasMethod()) {
yield new Property('METHOD', $this->getMethodTextValue($event->getMethod()));
}

foreach ($event->getAttachments() as $attachment) {
yield from $this->getAttachmentProperties($attachment);
}
Expand Down Expand Up @@ -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));
}
}
Loading