xref: /plugin/davcal/vendor/sabre/vobject/lib/Parser/Parser.php (revision a1a3b6794e0e143a4a8b51d3185ce2d339be61ab)
1*a1a3b679SAndreas Boehler<?php
2*a1a3b679SAndreas Boehler
3*a1a3b679SAndreas Boehlernamespace Sabre\VObject\Parser;
4*a1a3b679SAndreas Boehler
5*a1a3b679SAndreas Boehler/**
6*a1a3b679SAndreas Boehler * Abstract parser.
7*a1a3b679SAndreas Boehler *
8*a1a3b679SAndreas Boehler * This class serves as a base-class for the different parsers.
9*a1a3b679SAndreas Boehler *
10*a1a3b679SAndreas Boehler * @copyright Copyright (C) 2011-2015 fruux GmbH (https://fruux.com/).
11*a1a3b679SAndreas Boehler * @author Evert Pot (http://evertpot.com/)
12*a1a3b679SAndreas Boehler * @license http://sabre.io/license/ Modified BSD License
13*a1a3b679SAndreas Boehler */
14*a1a3b679SAndreas Boehlerabstract class Parser {
15*a1a3b679SAndreas Boehler
16*a1a3b679SAndreas Boehler    /**
17*a1a3b679SAndreas Boehler     * Turning on this option makes the parser more forgiving.
18*a1a3b679SAndreas Boehler     *
19*a1a3b679SAndreas Boehler     * In the case of the MimeDir parser, this means that the parser will
20*a1a3b679SAndreas Boehler     * accept slashes and underscores in property names, and it will also
21*a1a3b679SAndreas Boehler     * attempt to fix Microsoft vCard 2.1's broken line folding.
22*a1a3b679SAndreas Boehler     */
23*a1a3b679SAndreas Boehler    const OPTION_FORGIVING = 1;
24*a1a3b679SAndreas Boehler
25*a1a3b679SAndreas Boehler    /**
26*a1a3b679SAndreas Boehler     * If this option is turned on, any lines we cannot parse will be ignored
27*a1a3b679SAndreas Boehler     * by the reader.
28*a1a3b679SAndreas Boehler     */
29*a1a3b679SAndreas Boehler    const OPTION_IGNORE_INVALID_LINES = 2;
30*a1a3b679SAndreas Boehler
31*a1a3b679SAndreas Boehler    /**
32*a1a3b679SAndreas Boehler     * Bitmask of parser options
33*a1a3b679SAndreas Boehler     *
34*a1a3b679SAndreas Boehler     * @var int
35*a1a3b679SAndreas Boehler     */
36*a1a3b679SAndreas Boehler    protected $options;
37*a1a3b679SAndreas Boehler
38*a1a3b679SAndreas Boehler    /**
39*a1a3b679SAndreas Boehler     * Creates the parser.
40*a1a3b679SAndreas Boehler     *
41*a1a3b679SAndreas Boehler     * Optionally, it's possible to parse the input stream here.
42*a1a3b679SAndreas Boehler     *
43*a1a3b679SAndreas Boehler     * @param mixed $input
44*a1a3b679SAndreas Boehler     * @param int $options Any parser options (OPTION constants).
45*a1a3b679SAndreas Boehler     * @return void
46*a1a3b679SAndreas Boehler     */
47*a1a3b679SAndreas Boehler    public function __construct($input = null, $options = 0) {
48*a1a3b679SAndreas Boehler
49*a1a3b679SAndreas Boehler        if (!is_null($input)) {
50*a1a3b679SAndreas Boehler            $this->setInput($input);
51*a1a3b679SAndreas Boehler        }
52*a1a3b679SAndreas Boehler        $this->options = $options;
53*a1a3b679SAndreas Boehler    }
54*a1a3b679SAndreas Boehler
55*a1a3b679SAndreas Boehler    /**
56*a1a3b679SAndreas Boehler     * This method starts the parsing process.
57*a1a3b679SAndreas Boehler     *
58*a1a3b679SAndreas Boehler     * If the input was not supplied during construction, it's possible to pass
59*a1a3b679SAndreas Boehler     * it here instead.
60*a1a3b679SAndreas Boehler     *
61*a1a3b679SAndreas Boehler     * If either input or options are not supplied, the defaults will be used.
62*a1a3b679SAndreas Boehler     *
63*a1a3b679SAndreas Boehler     * @param mixed $input
64*a1a3b679SAndreas Boehler     * @param int|null $options
65*a1a3b679SAndreas Boehler     * @return array
66*a1a3b679SAndreas Boehler     */
67*a1a3b679SAndreas Boehler    abstract public function parse($input = null, $options = null);
68*a1a3b679SAndreas Boehler
69*a1a3b679SAndreas Boehler    /**
70*a1a3b679SAndreas Boehler     * Sets the input data
71*a1a3b679SAndreas Boehler     *
72*a1a3b679SAndreas Boehler     * @param mixed $input
73*a1a3b679SAndreas Boehler     * @return void
74*a1a3b679SAndreas Boehler     */
75*a1a3b679SAndreas Boehler    abstract public function setInput($input);
76*a1a3b679SAndreas Boehler
77*a1a3b679SAndreas Boehler}
78