1: <?php
2: declare(strict_types=1);
3:
4: namespace om;
5:
6: use Generator;
7: use om\ICal\Calendar;
8: use om\ICal\Item;
9: use om\ICal\Parser\Parser;
10:
11: /**
12: * Entry point of the iCalendar (RFC 5545) API.
13: *
14: * $calendar = ICal::parse($ics);
15: * foreach ($calendar->events() as $event) {
16: * foreach ($event->occurrencesBetween($from, $to) as $occurrence) { ... }
17: * }
18: *
19: * The permissive parser is used; see ICal::parser() for strict parsing, limits and warnings.
20: */
21: final class ICal {
22: /**
23: * The first calendar of the content.
24: *
25: * @throws ICal\Exception\SyntaxException when there is no VCALENDAR
26: */
27: public static function parse(string $content): Calendar {
28: return self::parser()->parse($content)->calendar();
29: }
30:
31: /**
32: * @throws \RuntimeException when the file cannot be read
33: */
34: public static function parseFile(string $file): Calendar {
35: return self::parser()->parseFile($file)->calendar();
36: }
37:
38: /**
39: * Events, tasks and journal entries of a large file one by one, see Parser::stream().
40: *
41: * @return Generator<int, Item>
42: */
43: public static function stream(string $file): Generator {
44: return self::parser()->stream($file);
45: }
46:
47: public static function parser(): Parser {
48: return new Parser();
49: }
50: }
51: