1
0

ABackend.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\Group\Backend;
  8. use OCP\GroupInterface;
  9. /**
  10. * @since 14.0.0
  11. */
  12. abstract class ABackend implements GroupInterface, IBatchMethodsBackend {
  13. /**
  14. * @deprecated 14.0.0
  15. * @since 14.0.0
  16. *
  17. * @param int $actions The action to check for
  18. * @return bool
  19. */
  20. public function implementsActions($actions): bool {
  21. $implements = 0;
  22. if ($this instanceof IAddToGroupBackend) {
  23. $implements |= GroupInterface::ADD_TO_GROUP;
  24. }
  25. if ($this instanceof ICountUsersBackend) {
  26. $implements |= GroupInterface::COUNT_USERS;
  27. }
  28. if ($this instanceof ICreateGroupBackend || $this instanceof ICreateNamedGroupBackend) {
  29. $implements |= GroupInterface::CREATE_GROUP;
  30. }
  31. if ($this instanceof IDeleteGroupBackend) {
  32. $implements |= GroupInterface::DELETE_GROUP;
  33. }
  34. if ($this instanceof IGroupDetailsBackend) {
  35. $implements |= GroupInterface::GROUP_DETAILS;
  36. }
  37. if ($this instanceof IIsAdminBackend) {
  38. $implements |= GroupInterface::IS_ADMIN;
  39. }
  40. if ($this instanceof IRemoveFromGroupBackend) {
  41. $implements |= GroupInterface::REMOVE_FROM_GOUP;
  42. }
  43. return (bool)($actions & $implements);
  44. }
  45. /**
  46. * @since 28.0.0
  47. */
  48. public function groupsExists(array $gids): array {
  49. return array_values(array_filter(
  50. $gids,
  51. fn (string $gid): bool => $this->groupExists($gid),
  52. ));
  53. }
  54. /**
  55. * @since 28.0.0
  56. */
  57. public function getGroupsDetails(array $gids): array {
  58. if (!($this instanceof IGroupDetailsBackend || $this->implementsActions(GroupInterface::GROUP_DETAILS))) {
  59. throw new \Exception("Should not have been called");
  60. }
  61. /** @var IGroupDetailsBackend $this */
  62. $groupData = [];
  63. foreach ($gids as $gid) {
  64. $groupData[$gid] = $this->getGroupDetails($gid);
  65. }
  66. return $groupData;
  67. }
  68. }