annotate vendor/sabre/vobject/lib/Reader.php @ 7:430dbd5346f7

vendor sabre as distributed
author Charlie Root
date Sat, 13 Jan 2018 09:06:10 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
1 <?php
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
2
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
3 namespace Sabre\VObject;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
4
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
5 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
6 * iCalendar/vCard/jCal/jCard reader object.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
7 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
8 * This object provides a few (static) convenience methods to quickly access
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
9 * the parsers.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
10 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
11 * @copyright Copyright (C) 2011-2015 fruux GmbH (https://fruux.com/).
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
12 * @author Evert Pot (http://evertpot.com/)
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
13 * @license http://sabre.io/license/ Modified BSD License
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
14 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
15 class Reader {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
16
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
17 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
18 * If this option is passed to the reader, it will be less strict about the
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
19 * validity of the lines.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
20 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
21 const OPTION_FORGIVING = 1;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
22
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
23 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
24 * If this option is turned on, any lines we cannot parse will be ignored
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
25 * by the reader.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
26 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
27 const OPTION_IGNORE_INVALID_LINES = 2;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
28
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
29 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
30 * Parses a vCard or iCalendar object, and returns the top component.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
31 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
32 * The options argument is a bitfield. Pass any of the OPTIONS constant to
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
33 * alter the parsers' behaviour.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
34 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
35 * You can either supply a string, or a readable stream for input.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
36 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
37 * @param string|resource $data
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
38 * @param int $options
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
39 * @return Document
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
40 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
41 static public function read($data, $options = 0) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
42
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
43 $parser = new Parser\MimeDir();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
44 $result = $parser->parse($data, $options);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
45
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
46 return $result;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
47
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
48 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
49
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
50 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
51 * Parses a jCard or jCal object, and returns the top component.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
52 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
53 * The options argument is a bitfield. Pass any of the OPTIONS constant to
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
54 * alter the parsers' behaviour.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
55 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
56 * You can either a string, a readable stream, or an array for it's input.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
57 * Specifying the array is useful if json_decode was already called on the
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
58 * input.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
59 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
60 * @param string|resource|array $data
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
61 * @param int $options
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
62 * @return Node
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
63 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
64 static public function readJson($data, $options = 0) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
65
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
66 $parser = new Parser\Json();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
67 $result = $parser->parse($data, $options);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
68
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
69 return $result;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
70
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
71 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
72
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
73 }