MkCalendar.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\CalDAV\Xml\Request;
  4. use Sabre\Xml\Reader;
  5. use Sabre\Xml\XmlDeserializable;
  6. /**
  7. * MKCALENDAR parser.
  8. *
  9. * This class parses the MKCALENDAR request, as defined in:
  10. *
  11. * https://tools.ietf.org/html/rfc4791#section-5.3.1
  12. *
  13. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  14. * @author Evert Pot (http://evertpot.com/)
  15. * @license http://sabre.io/license/ Modified BSD License
  16. */
  17. class MkCalendar implements XmlDeserializable
  18. {
  19. /**
  20. * The list of properties that will be set.
  21. *
  22. * @var array
  23. */
  24. public $properties = [];
  25. /**
  26. * Returns the list of properties the calendar will be initialized with.
  27. *
  28. * @return array
  29. */
  30. public function getProperties()
  31. {
  32. return $this->properties;
  33. }
  34. /**
  35. * The deserialize method is called during xml parsing.
  36. *
  37. * This method is called statically, this is because in theory this method
  38. * may be used as a type of constructor, or factory method.
  39. *
  40. * Often you want to return an instance of the current class, but you are
  41. * free to return other data as well.
  42. *
  43. * You are responsible for advancing the reader to the next element. Not
  44. * doing anything will result in a never-ending loop.
  45. *
  46. * If you just want to skip parsing for this element altogether, you can
  47. * just call $reader->next();
  48. *
  49. * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
  50. * the next element.
  51. *
  52. * @return mixed
  53. */
  54. public static function xmlDeserialize(Reader $reader)
  55. {
  56. $self = new self();
  57. $elementMap = $reader->elementMap;
  58. $elementMap['{DAV:}prop'] = 'Sabre\DAV\Xml\Element\Prop';
  59. $elementMap['{DAV:}set'] = 'Sabre\Xml\Element\KeyValue';
  60. $elems = $reader->parseInnerTree($elementMap);
  61. foreach ($elems as $elem) {
  62. if ('{DAV:}set' === $elem['name']) {
  63. $self->properties = array_merge($self->properties, $elem['value']['{DAV:}prop']);
  64. }
  65. }
  66. return $self;
  67. }
  68. }