1 | <?php |
||
12 | final class Event extends Component |
||
13 | { |
||
14 | /** @var array */ |
||
15 | private $alerts = []; |
||
16 | |||
17 | /** @var \DateTimeInterface */ |
||
18 | private $starts; |
||
19 | |||
20 | /** @var \DateTimeInterface */ |
||
21 | private $ends; |
||
22 | |||
23 | /** @var string */ |
||
24 | private $name; |
||
25 | |||
26 | /** @var string|null */ |
||
27 | private $description; |
||
28 | |||
29 | /** @var string|null */ |
||
30 | private $address; |
||
31 | |||
32 | /** @var string|null */ |
||
33 | private $addressName; |
||
34 | |||
35 | /** @var float|null */ |
||
36 | private $lat; |
||
37 | |||
38 | /** @var float|null */ |
||
39 | private $lng; |
||
40 | |||
41 | /** @var string */ |
||
42 | private $uuid; |
||
43 | |||
44 | /** @var \DateTimeInterface */ |
||
45 | private $created; |
||
46 | |||
47 | /** @var bool */ |
||
48 | private $withTimezone = false; |
||
49 | |||
50 | /** @var bool */ |
||
51 | private $isFullDay = false; |
||
52 | |||
53 | public static function create(string $name = null): Event |
||
57 | |||
58 | public function __construct(string $name = null) |
||
64 | |||
65 | public function getComponentType(): string |
||
69 | |||
70 | public function getRequiredProperties(): array |
||
78 | |||
79 | public function startsAt(DateTimeInterface $starts): Event |
||
85 | |||
86 | public function endsAt(DateTimeInterface $ends): Event |
||
92 | |||
93 | public function period(DateTimeInterface $starts, DateTimeInterface $ends): Event |
||
100 | |||
101 | public function name(string $name): Event |
||
107 | |||
108 | public function description(string $description): Event |
||
114 | |||
115 | public function address(string $address, string $name = null): Event |
||
125 | |||
126 | public function addressName(string $name): Event |
||
132 | |||
133 | public function coordinates(float $lat, float $lng): Event |
||
140 | |||
141 | public function uniqueIdentifier(string $uid): Event |
||
147 | |||
148 | public function createdAt(DateTimeInterface $created): Event |
||
154 | |||
155 | public function withTimezone(): Event |
||
161 | |||
162 | public function fullDay(): Event |
||
168 | |||
169 | public function alertMinutesBefore(int $minutes, string $message = null): Event |
||
180 | |||
181 | protected function payload(): ComponentPayload |
||
182 | { |
||
183 | $payload = ComponentPayload::create($this->getComponentType()) |
||
184 | ->textProperty('UID', $this->uuid) |
||
185 | ->textProperty('SUMMARY', $this->name) |
||
186 | ->textProperty('DESCRIPTION', $this->description) |
||
187 | ->textProperty('LOCATION', $this->address) |
||
188 | ->dateTimeProperty('DTSTART', $this->starts, ! $this->isFullDay, $this->withTimezone) |
||
189 | ->dateTimeProperty('DTEND', $this->ends, ! $this->isFullDay, $this->withTimezone) |
||
190 | ->dateTimeProperty('DTSTAMP', $this->created, true, $this->withTimezone) |
||
191 | ->subComponent(...$this->alerts); |
||
192 | |||
193 | $payload = $this->resolveLocationProperties($payload); |
||
194 | |||
195 | return $payload; |
||
196 | } |
||
197 | |||
198 | private function resolveLocationProperties(ComponentPayload $payload): ComponentPayload |
||
221 | } |
||
222 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: