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

Functionality for custom properties added #631

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
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
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;
}
}
Loading