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