You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TagList.php 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. * @author Vincent Petry <vincent@nextcloud.com>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCA\DAV\Connector\Sabre;
  26. use Sabre\Xml\Element;
  27. use Sabre\Xml\Reader;
  28. use Sabre\Xml\Writer;
  29. /**
  30. * TagList property
  31. *
  32. * This property contains multiple "tag" elements, each containing a tag name.
  33. */
  34. class TagList implements Element {
  35. public const NS_OWNCLOUD = 'http://owncloud.org/ns';
  36. /**
  37. * tags
  38. *
  39. * @var array
  40. */
  41. private $tags;
  42. /**
  43. * @param array $tags
  44. */
  45. public function __construct(array $tags) {
  46. $this->tags = $tags;
  47. }
  48. /**
  49. * Returns the tags
  50. *
  51. * @return array
  52. */
  53. public function getTags() {
  54. return $this->tags;
  55. }
  56. /**
  57. * The deserialize method is called during xml parsing.
  58. *
  59. * This method is called statictly, this is because in theory this method
  60. * may be used as a type of constructor, or factory method.
  61. *
  62. * Often you want to return an instance of the current class, but you are
  63. * free to return other data as well.
  64. *
  65. * You are responsible for advancing the reader to the next element. Not
  66. * doing anything will result in a never-ending loop.
  67. *
  68. * If you just want to skip parsing for this element altogether, you can
  69. * just call $reader->next();
  70. *
  71. * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
  72. * the next element.
  73. *
  74. * @param Reader $reader
  75. * @return mixed
  76. */
  77. public static function xmlDeserialize(Reader $reader) {
  78. $tags = [];
  79. $tree = $reader->parseInnerTree();
  80. if ($tree === null) {
  81. return null;
  82. }
  83. foreach ($tree as $elem) {
  84. if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') {
  85. $tags[] = $elem['value'];
  86. }
  87. }
  88. return new self($tags);
  89. }
  90. /**
  91. * The xmlSerialize metod is called during xml writing.
  92. *
  93. * Use the $writer argument to write its own xml serialization.
  94. *
  95. * An important note: do _not_ create a parent element. Any element
  96. * implementing XmlSerializble should only ever write what's considered
  97. * its 'inner xml'.
  98. *
  99. * The parent of the current element is responsible for writing a
  100. * containing element.
  101. *
  102. * This allows serializers to be re-used for different element names.
  103. *
  104. * If you are opening new elements, you must also close them again.
  105. *
  106. * @param Writer $writer
  107. * @return void
  108. */
  109. public function xmlSerialize(Writer $writer) {
  110. foreach ($this->tags as $tag) {
  111. $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag);
  112. }
  113. }
  114. }