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