Lock.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\DAV\Xml\Request;
  4. use Sabre\DAV\Locks\LockInfo;
  5. use Sabre\Xml\Element\KeyValue;
  6. use Sabre\Xml\Reader;
  7. use Sabre\Xml\XmlDeserializable;
  8. /**
  9. * WebDAV LOCK request parser.
  10. *
  11. * This class parses the {DAV:}lockinfo request, as defined in:
  12. *
  13. * http://tools.ietf.org/html/rfc4918#section-9.10
  14. *
  15. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  16. * @author Evert Pot (http://evertpot.com/)
  17. * @license http://sabre.io/license/ Modified BSD License
  18. */
  19. class Lock implements XmlDeserializable
  20. {
  21. /**
  22. * Owner of the lock.
  23. *
  24. * @var string
  25. */
  26. public $owner;
  27. /**
  28. * Scope of the lock.
  29. *
  30. * Either LockInfo::SHARED or LockInfo::EXCLUSIVE
  31. *
  32. * @var int
  33. */
  34. public $scope;
  35. /**
  36. * The deserialize method is called during xml parsing.
  37. *
  38. * This method is called statically, this is because in theory this method
  39. * may be used as a type of constructor, or factory method.
  40. *
  41. * Often you want to return an instance of the current class, but you are
  42. * free to return other data as well.
  43. *
  44. * You are responsible for advancing the reader to the next element. Not
  45. * doing anything will result in a never-ending loop.
  46. *
  47. * If you just want to skip parsing for this element altogether, you can
  48. * just call $reader->next();
  49. *
  50. * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
  51. * the next element.
  52. *
  53. * @return mixed
  54. */
  55. public static function xmlDeserialize(Reader $reader)
  56. {
  57. $reader->pushContext();
  58. $reader->elementMap['{DAV:}owner'] = 'Sabre\\Xml\\Element\\XmlFragment';
  59. $values = KeyValue::xmlDeserialize($reader);
  60. $reader->popContext();
  61. $new = new self();
  62. $new->owner = !empty($values['{DAV:}owner']) ? $values['{DAV:}owner']->getXml() : null;
  63. $new->scope = LockInfo::SHARED;
  64. if (isset($values['{DAV:}lockscope'])) {
  65. foreach ($values['{DAV:}lockscope'] as $elem) {
  66. if ('{DAV:}exclusive' === $elem['name']) {
  67. $new->scope = LockInfo::EXCLUSIVE;
  68. }
  69. }
  70. }
  71. return $new;
  72. }
  73. }