Reader.php 1.9 KB

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