1: <?php
2: declare(strict_types=1);
3:
4: namespace om\ICal\Value;
5:
6: use DateInterval;
7: use om\ICal\Parameters;
8: use Stringable;
9:
10: /**
11: * RELATED-TO of a component (RFC 5545, section 3.8.4.5, updated by RFC 9253, section 9.1).
12: */
13: final readonly class Relation implements Stringable {
14: /**
15: * @param string $value the UID of the related component, or a URI, see valueType()
16: */
17: public function __construct(
18: public string $value,
19: public Parameters $parameters,
20: ) {
21: }
22:
23: /**
24: * Type of the value: UID (default), URI or TEXT.
25: */
26: public function valueType(): string {
27: return strtoupper($this->parameters->get('VALUE') ?? 'UID');
28: }
29:
30: /**
31: * RELTYPE in upper case: PARENT (default), CHILD, SIBLING, the RFC 9253 types FINISHTOSTART, FINISHTOFINISH,
32: * STARTTOFINISH, STARTTOSTART, FIRST, NEXT, DEPENDS-ON, REFID, CONCEPT, SNOOZE of RFC 9074, or an X- value.
33: */
34: public function type(): string {
35: return strtoupper($this->parameters->get('RELTYPE') ?? 'PARENT');
36: }
37:
38: /**
39: * GAP (RFC 9253): the lag (positive) or lead (negative) time between the components of a temporal relation.
40: */
41: public function gap(): ?DateInterval {
42: $gap = $this->parameters->get('GAP');
43: return $gap === null ? null : Duration::parse($gap);
44: }
45:
46: public function __toString(): string {
47: return $this->value;
48: }
49: }
50: