LanguageTuple.php 942 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\Translation;
  8. use JsonSerializable;
  9. /**
  10. * @since 26.0.0
  11. */
  12. class LanguageTuple implements JsonSerializable {
  13. /**
  14. * @since 26.0.0
  15. */
  16. public function __construct(
  17. private string $from,
  18. private string $fromLabel,
  19. private string $to,
  20. private string $toLabel
  21. ) {
  22. }
  23. /**
  24. * @since 26.0.0
  25. * @return array{from: string, fromLabel: string, to: string, toLabel: string}
  26. */
  27. public function jsonSerialize(): array {
  28. return [
  29. 'from' => $this->from,
  30. 'fromLabel' => $this->fromLabel,
  31. 'to' => $this->to,
  32. 'toLabel' => $this->toLabel,
  33. ];
  34. }
  35. /**
  36. * @since 26.0.0
  37. */
  38. public static function fromArray(array $data): LanguageTuple {
  39. return new self(
  40. $data['from'],
  41. $data['fromLabel'],
  42. $data['to'],
  43. $data['toLabel'],
  44. );
  45. }
  46. }