Parser.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. /**
  15. * Turning on this option makes the parser more forgiving.
  16. *
  17. * In the case of the MimeDir parser, this means that the parser will
  18. * accept slashes and underscores in property names, and it will also
  19. * attempt to fix Microsoft vCard 2.1's broken line folding.
  20. */
  21. const OPTION_FORGIVING = 1;
  22. /**
  23. * If this option is turned on, any lines we cannot parse will be ignored
  24. * by the reader.
  25. */
  26. const OPTION_IGNORE_INVALID_LINES = 2;
  27. /**
  28. * Bitmask of parser options.
  29. *
  30. * @var int
  31. */
  32. protected $options;
  33. /**
  34. * Creates the parser.
  35. *
  36. * Optionally, it's possible to parse the input stream here.
  37. *
  38. * @param mixed $input
  39. * @param int $options any parser options (OPTION constants)
  40. */
  41. public function __construct($input = null, $options = 0)
  42. {
  43. if (!is_null($input)) {
  44. $this->setInput($input);
  45. }
  46. $this->options = $options;
  47. }
  48. /**
  49. * This method starts the parsing process.
  50. *
  51. * If the input was not supplied during construction, it's possible to pass
  52. * it here instead.
  53. *
  54. * If either input or options are not supplied, the defaults will be used.
  55. *
  56. * @param mixed $input
  57. * @param int $options
  58. *
  59. * @return array
  60. */
  61. abstract public function parse($input = null, $options = 0);
  62. /**
  63. * Sets the input data.
  64. *
  65. * @param mixed $input
  66. */
  67. abstract public function setInput($input);
  68. }