From 50b1cca8662136d5e84ed650b754e4634911bb1d Mon Sep 17 00:00:00 2001 From: Clemens Neubauer Date: Sat, 17 Aug 2024 07:44:59 +0000 Subject: [PATCH] Functionality for custom properties added --- src/Presentation/Factory/CalendarFactory.php | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/Presentation/Factory/CalendarFactory.php b/src/Presentation/Factory/CalendarFactory.php index 28c5affe..ba5e07e4 100644 --- a/src/Presentation/Factory/CalendarFactory.php +++ b/src/Presentation/Factory/CalendarFactory.php @@ -20,6 +20,7 @@ class CalendarFactory { + private array $customCalProps; private EventFactory $eventFactory; private TimeZoneFactory $timeZoneFactory; @@ -27,6 +28,7 @@ public function __construct(EventFactory $eventFactory = null, TimeZoneFactory $ { $this->eventFactory = $eventFactory ?? new EventFactory(); $this->timeZoneFactory = $timeZoneFactory ?? new TimeZoneFactory(); + $this->clearCustomCalProps(); } public function createCalendar(Calendar $calendar): Component @@ -62,5 +64,34 @@ protected function getProperties(Calendar $calendar): Generator /* @see http://msdn.microsoft.com/en-us/library/ee178699(v=exchg.80).aspx */ yield new Property('X-PUBLISHED-TTL', new DurationValue($publishedTTL)); } + + // Remove obsolete keys in custom properties + unset($this->customCalProps['PRODID']); + unset($this->customCalProps['VERSION']); + unset($this->customCalProps['CALSCALE']); + if ($publishedTTL) { + unset($this->customCalProps['X-PUBLISHED-TTL']); + } + + // Additional custom properties + reset($this->customCalProps); + while ($value = current($this->customCalProps)) { + yield new Property(key($this->customCalProps), new TextValue($value)); + next($this->customCalProps); + } + } + + /** + * @return void + */ + public function clearCustomCalProps() { + $this->customCalProps = []; + } + + /** + * @return void + */ + public function setCustomCalProp(string $key, string $value): void { + $this->customCalProps[$key] = $value; } }