Parser.php 1.9 KB

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