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.

OCMResource.php 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2023, Maxence Lange <maxence@artificial-owl.com>
  5. *
  6. * @author Maxence Lange <maxence@artificial-owl.com>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OC\OCM\Model;
  25. use JsonSerializable;
  26. use OCP\OCM\IOCMResource;
  27. /**
  28. * @since 28.0.0
  29. */
  30. class OCMResource implements IOCMResource, JsonSerializable {
  31. private string $name = '';
  32. /** @var string[] */
  33. private array $shareTypes = [];
  34. /** @var array<string, string> */
  35. private array $protocols = [];
  36. /**
  37. * @param string $name
  38. *
  39. * @return OCMResource
  40. */
  41. public function setName(string $name): self {
  42. $this->name = $name;
  43. return $this;
  44. }
  45. /**
  46. * @return string
  47. */
  48. public function getName(): string {
  49. return $this->name;
  50. }
  51. /**
  52. * @param string[] $shareTypes
  53. *
  54. * @return OCMResource
  55. */
  56. public function setShareTypes(array $shareTypes): self {
  57. $this->shareTypes = $shareTypes;
  58. return $this;
  59. }
  60. /**
  61. * @return string[]
  62. */
  63. public function getShareTypes(): array {
  64. return $this->shareTypes;
  65. }
  66. /**
  67. * @param array<string, string> $protocols
  68. *
  69. * @return $this
  70. */
  71. public function setProtocols(array $protocols): self {
  72. $this->protocols = $protocols;
  73. return $this;
  74. }
  75. /**
  76. * @return array<string, string>
  77. */
  78. public function getProtocols(): array {
  79. return $this->protocols;
  80. }
  81. /**
  82. * import data from an array
  83. *
  84. * @param array $data
  85. *
  86. * @return self
  87. * @see self::jsonSerialize()
  88. */
  89. public function import(array $data): self {
  90. return $this->setName((string)($data['name'] ?? ''))
  91. ->setShareTypes($data['shareTypes'] ?? [])
  92. ->setProtocols($data['protocols'] ?? []);
  93. }
  94. /**
  95. *
  96. * @return array{
  97. * name: string,
  98. * shareTypes: string[],
  99. * protocols: array<string, string>
  100. * }
  101. */
  102. public function jsonSerialize(): array {
  103. return [
  104. 'name' => $this->getName(),
  105. 'shareTypes' => $this->getShareTypes(),
  106. 'protocols' => $this->getProtocols()
  107. ];
  108. }
  109. }