<?php
 namespace Eluceo\iCal\Domain\Entity; use DateInterval; use Eluceo\iCal\Domain\Collection\Events; use Eluceo\iCal\Domain\Collection\EventsArray; use Eluceo\iCal\Domain\Collection\EventsGenerator; use InvalidArgumentException; use Iterator; class Calendar { private string $productIdentifier = '-//eluceo/ical//2.0/EN'; private ?DateInterval $publishedTTL = null; private Events $events; private array $timeZones = []; public function __construct($events = []) { $this->events = $this->ensureEventsObject($events); } private function ensureEventsObject($events = []): Events { if ($events instanceof Events) { return $events; } if (is_array($events)) { return new EventsArray($events); } if ($events instanceof Iterator) { return new EventsGenerator($events); } throw new InvalidArgumentException('$events must be an array, an object implementing Iterator or an instance of Events.'); } public function getPublishedTTL(): ?DateInterval { return $this->publishedTTL; } public function setPublishedTTL(?DateInterval $ttl): self { $this->publishedTTL = $ttl; return $this; } public function getProductIdentifier(): string { return $this->productIdentifier; } public function setProductIdentifier(string $productIdentifier): self { $this->productIdentifier = $productIdentifier; return $this; } public function getEvents(): Events { return $this->events; } public function addEvent(Event $event): self { $this->events->addEvent($event); return $this; } public function getTimeZones(): array { return $this->timeZones; } public function addTimeZone(TimeZone $timeZone): self { $this->timeZones[] = $timeZone; return $this; } } 