1
0

ShareAttributes.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * @author Piotr Mrowczynski <piotr@owncloud.com>
  4. *
  5. * @copyright Copyright (c) 2019, ownCloud GmbH
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace OC\Share20;
  22. use OCP\Share\IAttributes;
  23. class ShareAttributes implements IAttributes {
  24. /** @var array */
  25. private $attributes;
  26. public function __construct() {
  27. $this->attributes = [];
  28. }
  29. /**
  30. * @inheritdoc
  31. */
  32. public function setAttribute($scope, $key, $enabled) {
  33. if (!\array_key_exists($scope, $this->attributes)) {
  34. $this->attributes[$scope] = [];
  35. }
  36. $this->attributes[$scope][$key] = $enabled;
  37. return $this;
  38. }
  39. /**
  40. * @inheritdoc
  41. */
  42. public function getAttribute($scope, $key) {
  43. if (\array_key_exists($scope, $this->attributes) &&
  44. \array_key_exists($key, $this->attributes[$scope])) {
  45. return $this->attributes[$scope][$key];
  46. }
  47. return null;
  48. }
  49. /**
  50. * @inheritdoc
  51. */
  52. public function toArray() {
  53. $result = [];
  54. foreach ($this->attributes as $scope => $keys) {
  55. foreach ($keys as $key => $enabled) {
  56. $result[] = [
  57. "scope" => $scope,
  58. "key" => $key,
  59. "enabled" => $enabled
  60. ];
  61. }
  62. }
  63. return $result;
  64. }
  65. }