1
0

OCMResource.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\OCM\Model;
  8. use OCP\OCM\IOCMResource;
  9. /**
  10. * @since 28.0.0
  11. */
  12. class OCMResource implements IOCMResource {
  13. private string $name = '';
  14. /** @var list<string> */
  15. private array $shareTypes = [];
  16. /** @var array<string, string> */
  17. private array $protocols = [];
  18. /**
  19. * @param string $name
  20. *
  21. * @return $this
  22. */
  23. public function setName(string $name): static {
  24. $this->name = $name;
  25. return $this;
  26. }
  27. /**
  28. * @return string
  29. */
  30. public function getName(): string {
  31. return $this->name;
  32. }
  33. /**
  34. * @param list<string> $shareTypes
  35. *
  36. * @return $this
  37. */
  38. public function setShareTypes(array $shareTypes): static {
  39. $this->shareTypes = $shareTypes;
  40. return $this;
  41. }
  42. /**
  43. * @return list<string>
  44. */
  45. public function getShareTypes(): array {
  46. return $this->shareTypes;
  47. }
  48. /**
  49. * @param array<string, string> $protocols
  50. *
  51. * @return $this
  52. */
  53. public function setProtocols(array $protocols): static {
  54. $this->protocols = $protocols;
  55. return $this;
  56. }
  57. /**
  58. * @return array<string, string>
  59. */
  60. public function getProtocols(): array {
  61. return $this->protocols;
  62. }
  63. /**
  64. * import data from an array
  65. *
  66. * @param array $data
  67. *
  68. * @return $this
  69. * @see self::jsonSerialize()
  70. */
  71. public function import(array $data): static {
  72. return $this->setName((string)($data['name'] ?? ''))
  73. ->setShareTypes($data['shareTypes'] ?? [])
  74. ->setProtocols($data['protocols'] ?? []);
  75. }
  76. /**
  77. * @return array{
  78. * name: string,
  79. * shareTypes: list<string>,
  80. * protocols: array<string, string>
  81. * }
  82. */
  83. public function jsonSerialize(): array {
  84. return [
  85. 'name' => $this->getName(),
  86. 'shareTypes' => $this->getShareTypes(),
  87. 'protocols' => $this->getProtocols()
  88. ];
  89. }
  90. }