1
0

OCMResource.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 OCP\OCM\IOCMResource;
  26. /**
  27. * @since 28.0.0
  28. */
  29. class OCMResource implements IOCMResource {
  30. private string $name = '';
  31. /** @var string[] */
  32. private array $shareTypes = [];
  33. /** @var array<string, string> */
  34. private array $protocols = [];
  35. /**
  36. * @param string $name
  37. *
  38. * @return $this
  39. */
  40. public function setName(string $name): static {
  41. $this->name = $name;
  42. return $this;
  43. }
  44. /**
  45. * @return string
  46. */
  47. public function getName(): string {
  48. return $this->name;
  49. }
  50. /**
  51. * @param string[] $shareTypes
  52. *
  53. * @return $this
  54. */
  55. public function setShareTypes(array $shareTypes): static {
  56. $this->shareTypes = $shareTypes;
  57. return $this;
  58. }
  59. /**
  60. * @return string[]
  61. */
  62. public function getShareTypes(): array {
  63. return $this->shareTypes;
  64. }
  65. /**
  66. * @param array<string, string> $protocols
  67. *
  68. * @return $this
  69. */
  70. public function setProtocols(array $protocols): static {
  71. $this->protocols = $protocols;
  72. return $this;
  73. }
  74. /**
  75. * @return array<string, string>
  76. */
  77. public function getProtocols(): array {
  78. return $this->protocols;
  79. }
  80. /**
  81. * import data from an array
  82. *
  83. * @param array $data
  84. *
  85. * @return $this
  86. * @see self::jsonSerialize()
  87. */
  88. public function import(array $data): static {
  89. return $this->setName((string)($data['name'] ?? ''))
  90. ->setShareTypes($data['shareTypes'] ?? [])
  91. ->setProtocols($data['protocols'] ?? []);
  92. }
  93. /**
  94. * @return array{
  95. * name: string,
  96. * shareTypes: string[],
  97. * protocols: array<string, string>
  98. * }
  99. */
  100. public function jsonSerialize(): array {
  101. return [
  102. 'name' => $this->getName(),
  103. 'shareTypes' => $this->getShareTypes(),
  104. 'protocols' => $this->getProtocols()
  105. ];
  106. }
  107. }