| 1: | <?php |
| 2: | declare(strict_types=1); |
| 3: | |
| 4: | namespace om\ICal; |
| 5: | |
| 6: | use InvalidArgumentException; |
| 7: | use om\ICal\Value\PropertyFactory; |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | final class Location { |
| 17: | |
| 18: | |
| 19: | |
| 20: | public function __construct( |
| 21: | public readonly Component $component, |
| 22: | private readonly Calendar $calendar, |
| 23: | ) { |
| 24: | } |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | |
| 35: | public static function new( |
| 36: | ?string $uid = null, |
| 37: | ?string $name = null, |
| 38: | ?string $description = null, |
| 39: | ?array $geo = null, |
| 40: | iterable $types = [], |
| 41: | ?string $url = null, |
| 42: | array $properties = [], |
| 43: | ): self { |
| 44: | $builder = (new ComponentBuilder('VLOCATION')) |
| 45: | ->text('UID', ComponentBuilder::uid($uid)) |
| 46: | ->text('NAME', $name) |
| 47: | ->text('DESCRIPTION', $description) |
| 48: | ->add($geo === null ? null : PropertyFactory::geo($geo), PropertyFactory::texts('LOCATION-TYPE', $types)) |
| 49: | ->uri('URL', $url); |
| 50: | return new self($builder->build($properties), new Calendar()); |
| 51: | } |
| 52: | |
| 53: | public function property(string $name): ?Property { |
| 54: | return $this->component->property($name); |
| 55: | } |
| 56: | |
| 57: | |
| 58: | |
| 59: | |
| 60: | public function value(string $name): mixed { |
| 61: | $property = $this->property($name); |
| 62: | return $property === null ? null : $this->calendar->values()->value($property); |
| 63: | } |
| 64: | |
| 65: | public function uid(): ?string { |
| 66: | return $this->text('UID'); |
| 67: | } |
| 68: | |
| 69: | |
| 70: | public function name(): ?string { |
| 71: | return $this->text('NAME'); |
| 72: | } |
| 73: | |
| 74: | public function description(): ?string { |
| 75: | return $this->text('DESCRIPTION'); |
| 76: | } |
| 77: | |
| 78: | |
| 79: | |
| 80: | |
| 81: | |
| 82: | |
| 83: | public function types(): array { |
| 84: | $property = $this->property('LOCATION-TYPE'); |
| 85: | return $property === null ? [] : $this->calendar->values()->texts($property); |
| 86: | } |
| 87: | |
| 88: | public function url(): ?string { |
| 89: | $property = $this->property('URL'); |
| 90: | return $property === null ? null : $this->calendar->values()->uri($property); |
| 91: | } |
| 92: | |
| 93: | private function text(string $name): ?string { |
| 94: | $property = $this->property($name); |
| 95: | return $property === null ? null : $this->calendar->values()->text($property); |
| 96: | } |
| 97: | } |
| 98: | |