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