UuidInterface.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * This file is part of the ramsey/uuid library
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. *
  8. * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com>
  9. * @license http://opensource.org/licenses/MIT MIT
  10. */
  11. declare(strict_types=1);
  12. namespace Ramsey\Uuid;
  13. use JsonSerializable;
  14. use Ramsey\Uuid\Fields\FieldsInterface;
  15. use Ramsey\Uuid\Type\Hexadecimal;
  16. use Ramsey\Uuid\Type\Integer as IntegerObject;
  17. use Serializable;
  18. use Stringable;
  19. /**
  20. * A UUID is a universally unique identifier adhering to an agreed-upon representation format and standard for generation
  21. *
  22. * @immutable
  23. */
  24. interface UuidInterface extends
  25. DeprecatedUuidInterface,
  26. JsonSerializable,
  27. Serializable,
  28. Stringable
  29. {
  30. /**
  31. * Returns -1, 0, or 1 if the UUID is less than, equal to, or greater than the other UUID
  32. *
  33. * The first of two UUIDs is greater than the second if the most significant field in which the UUIDs differ is
  34. * greater for the first UUID.
  35. *
  36. * @param UuidInterface $other The UUID to compare
  37. *
  38. * @return int<-1,1> -1, 0, or 1 if the UUID is less than, equal to, or greater than $other
  39. */
  40. public function compareTo(UuidInterface $other): int;
  41. /**
  42. * Returns true if the UUID is equal to the provided object
  43. *
  44. * The result is true if and only if the argument is not null, is a UUID object, has the same variant, and contains
  45. * the same value, bit-for-bit, as the UUID.
  46. *
  47. * @param object | null $other An object to test for equality with this UUID
  48. *
  49. * @return bool True if the other object is equal to this UUID
  50. */
  51. public function equals(?object $other): bool;
  52. /**
  53. * Returns the binary string representation of the UUID
  54. *
  55. * @return non-empty-string
  56. *
  57. * @pure
  58. */
  59. public function getBytes(): string;
  60. /**
  61. * Returns the fields that comprise this UUID
  62. */
  63. public function getFields(): FieldsInterface;
  64. /**
  65. * Returns the hexadecimal representation of the UUID
  66. */
  67. public function getHex(): Hexadecimal;
  68. /**
  69. * Returns the integer representation of the UUID
  70. */
  71. public function getInteger(): IntegerObject;
  72. /**
  73. * Returns the string standard representation of the UUID as a URN
  74. *
  75. * @link http://en.wikipedia.org/wiki/Uniform_Resource_Name Uniform Resource Name
  76. * @link https://www.rfc-editor.org/rfc/rfc9562.html#section-4 RFC 9562, 4. UUID Format
  77. * @link https://www.rfc-editor.org/rfc/rfc9562.html#section-7 RFC 9562, 7. IANA Considerations
  78. * @link https://www.rfc-editor.org/rfc/rfc4122.html#section-3 RFC 4122, 3. Namespace Registration Template
  79. */
  80. public function getUrn(): string;
  81. /**
  82. * Returns the string standard representation of the UUID
  83. *
  84. * @return non-empty-string
  85. *
  86. * @pure
  87. */
  88. public function toString(): string;
  89. /**
  90. * Casts the UUID to the string standard representation
  91. *
  92. * @return non-empty-string
  93. *
  94. * @pure
  95. */
  96. public function __toString(): string;
  97. }