1
0

JsonSerializer.php 793 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\EventDispatcher;
  8. use OCP\Files\FileInfo;
  9. use OCP\IUser;
  10. /**
  11. * Contains helper static methods to serialize OCP classes into arrays to pass json_encode.
  12. * Useful for events implementing \JsonSerializable.
  13. *
  14. * @since 30.0.0
  15. */
  16. final class JsonSerializer {
  17. /**
  18. * @since 30.0.0
  19. */
  20. public static function serializeFileInfo(FileInfo $node): array {
  21. return [
  22. 'id' => $node->getId(),
  23. 'path' => $node->getPath(),
  24. ];
  25. }
  26. /**
  27. * @since 30.0.0
  28. */
  29. public static function serializeUser(IUser $user): array {
  30. return [
  31. 'uid' => $user->getUID(),
  32. 'displayName' => $user->getDisplayName(),
  33. ];
  34. }
  35. }