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.

ShareTypeList.php 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Vincent Petry <vincent@nextcloud.com>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OCA\DAV\Connector\Sabre;
  24. use Sabre\Xml\Element;
  25. use Sabre\Xml\Reader;
  26. use Sabre\Xml\Writer;
  27. /**
  28. * ShareTypeList property
  29. *
  30. * This property contains multiple "share-type" elements, each containing a share type.
  31. */
  32. class ShareTypeList implements Element {
  33. public const NS_OWNCLOUD = 'http://owncloud.org/ns';
  34. /**
  35. * Share types
  36. *
  37. * @var int[]
  38. */
  39. private $shareTypes;
  40. /**
  41. * @param int[] $shareTypes
  42. */
  43. public function __construct($shareTypes) {
  44. $this->shareTypes = $shareTypes;
  45. }
  46. /**
  47. * Returns the share types
  48. *
  49. * @return int[]
  50. */
  51. public function getShareTypes() {
  52. return $this->shareTypes;
  53. }
  54. /**
  55. * The deserialize method is called during xml parsing.
  56. *
  57. * @param Reader $reader
  58. * @return mixed
  59. */
  60. public static function xmlDeserialize(Reader $reader) {
  61. $shareTypes = [];
  62. $tree = $reader->parseInnerTree();
  63. if ($tree === null) {
  64. return null;
  65. }
  66. foreach ($tree as $elem) {
  67. if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}share-type') {
  68. $shareTypes[] = (int)$elem['value'];
  69. }
  70. }
  71. return new self($shareTypes);
  72. }
  73. /**
  74. * The xmlSerialize metod is called during xml writing.
  75. *
  76. * @param Writer $writer
  77. * @return void
  78. */
  79. public function xmlSerialize(Writer $writer) {
  80. foreach ($this->shareTypes as $shareType) {
  81. $writer->writeElement('{' . self::NS_OWNCLOUD . '}share-type', $shareType);
  82. }
  83. }
  84. }