ABackend.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2018 Roeland Jago Douma <roeland@famdouma.nl>
  5. *
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. * @author Carl Schwan <carl@carlschwan.eu>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCP\Group\Backend;
  26. use OCP\GroupInterface;
  27. /**
  28. * @since 14.0.0
  29. */
  30. abstract class ABackend implements GroupInterface, IBatchMethodsBackend {
  31. /**
  32. * @deprecated 14.0.0
  33. * @since 14.0.0
  34. *
  35. * @param int $actions The action to check for
  36. * @return bool
  37. */
  38. public function implementsActions($actions): bool {
  39. $implements = 0;
  40. if ($this instanceof IAddToGroupBackend) {
  41. $implements |= GroupInterface::ADD_TO_GROUP;
  42. }
  43. if ($this instanceof ICountUsersBackend) {
  44. $implements |= GroupInterface::COUNT_USERS;
  45. }
  46. if ($this instanceof ICreateGroupBackend || $this instanceof ICreateNamedGroupBackend) {
  47. $implements |= GroupInterface::CREATE_GROUP;
  48. }
  49. if ($this instanceof IDeleteGroupBackend) {
  50. $implements |= GroupInterface::DELETE_GROUP;
  51. }
  52. if ($this instanceof IGroupDetailsBackend) {
  53. $implements |= GroupInterface::GROUP_DETAILS;
  54. }
  55. if ($this instanceof IIsAdminBackend) {
  56. $implements |= GroupInterface::IS_ADMIN;
  57. }
  58. if ($this instanceof IRemoveFromGroupBackend) {
  59. $implements |= GroupInterface::REMOVE_FROM_GOUP;
  60. }
  61. return (bool)($actions & $implements);
  62. }
  63. /**
  64. * @since 28.0.0
  65. */
  66. public function groupsExists(array $gids): array {
  67. return array_values(array_filter(
  68. $gids,
  69. fn (string $gid): bool => $this->groupExists($gid),
  70. ));
  71. }
  72. /**
  73. * @since 28.0.0
  74. */
  75. public function getGroupsDetails(array $gids): array {
  76. if (!($this instanceof IGroupDetailsBackend || $this->implementsActions(GroupInterface::GROUP_DETAILS))) {
  77. throw new \Exception("Should not have been called");
  78. }
  79. /** @var IGroupDetailsBackend $this */
  80. $groupData = [];
  81. foreach ($gids as $gid) {
  82. $groupData[$gid] = $this->getGroupDetails($gid);
  83. }
  84. return $groupData;
  85. }
  86. }