Skip to content

Commit

Permalink
Functionality for custom properties added
Browse files Browse the repository at this point in the history
  • Loading branch information
cn-tools committed Aug 17, 2024
1 parent eea3cb3 commit 50b1cca
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Presentation/Factory/CalendarFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@

class CalendarFactory
{
private array $customCalProps;
private EventFactory $eventFactory;
private TimeZoneFactory $timeZoneFactory;

public function __construct(EventFactory $eventFactory = null, TimeZoneFactory $timeZoneFactory = null)
{
$this->eventFactory = $eventFactory ?? new EventFactory();
$this->timeZoneFactory = $timeZoneFactory ?? new TimeZoneFactory();
$this->clearCustomCalProps();
}

public function createCalendar(Calendar $calendar): Component
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 50b1cca

Please sign in to comment.