ShareAttributes.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2023-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2019-2022 ownCloud GmbH
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\Share20;
  8. use OCP\Share\IAttributes;
  9. class ShareAttributes implements IAttributes {
  10. /** @var array */
  11. private $attributes;
  12. public function __construct() {
  13. $this->attributes = [];
  14. }
  15. /**
  16. * @inheritdoc
  17. */
  18. public function setAttribute(string $scope, string $key, mixed $value): IAttributes {
  19. if (!\array_key_exists($scope, $this->attributes)) {
  20. $this->attributes[$scope] = [];
  21. }
  22. $this->attributes[$scope][$key] = $value;
  23. return $this;
  24. }
  25. /**
  26. * @inheritdoc
  27. */
  28. public function getAttribute(string $scope, string $key): mixed {
  29. if (\array_key_exists($scope, $this->attributes) &&
  30. \array_key_exists($key, $this->attributes[$scope])) {
  31. return $this->attributes[$scope][$key];
  32. }
  33. return null;
  34. }
  35. /**
  36. * @inheritdoc
  37. */
  38. public function toArray(): array {
  39. $result = [];
  40. foreach ($this->attributes as $scope => $keys) {
  41. foreach ($keys as $key => $value) {
  42. $result[] = [
  43. 'scope' => $scope,
  44. 'key' => $key,
  45. 'value' => $value,
  46. ];
  47. }
  48. }
  49. return $result;
  50. }
  51. }