Identifier.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php declare(strict_types=1);
  2. namespace Grav\Framework\Object\Identifiers;
  3. use Grav\Framework\Contracts\Object\IdentifierInterface;
  4. /**
  5. * Interface IdentifierInterface
  6. *
  7. * @template T of object
  8. */
  9. class Identifier implements IdentifierInterface
  10. {
  11. /** @var string */
  12. private $id;
  13. /** @var string */
  14. private $type;
  15. /**
  16. * IdentifierInterface constructor.
  17. * @param string $id
  18. * @param string $type
  19. */
  20. public function __construct(string $id, string $type)
  21. {
  22. $this->id = $id;
  23. $this->type = $type;
  24. }
  25. /**
  26. * @return string
  27. * @phpstan-pure
  28. */
  29. public function getId(): string
  30. {
  31. return $this->id;
  32. }
  33. /**
  34. * @return string
  35. * @phpstan-pure
  36. */
  37. public function getType(): string
  38. {
  39. return $this->type;
  40. }
  41. /**
  42. * @return array
  43. */
  44. public function jsonSerialize(): array
  45. {
  46. return [
  47. 'type' => $this->type,
  48. 'id' => $this->id
  49. ];
  50. }
  51. /**
  52. * @return array
  53. */
  54. public function __debugInfo(): array
  55. {
  56. return $this->jsonSerialize();
  57. }
  58. }