Nenhuma descrição

UuidFactoryInterface.php 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. * @link https://benramsey.com/projects/ramsey-uuid/ Documentation
  11. * @link https://packagist.org/packages/ramsey/uuid Packagist
  12. * @link https://github.com/ramsey/uuid GitHub
  13. */
  14. namespace Ramsey\Uuid;
  15. use Exception;
  16. use InvalidArgumentException;
  17. use Ramsey\Uuid\Exception\InvalidUuidStringException;
  18. use Ramsey\Uuid\Exception\UnsatisfiedDependencyException;
  19. /**
  20. * UuidFactoryInterface defines common functionality all `UuidFactory` instances
  21. * must implement
  22. */
  23. interface UuidFactoryInterface
  24. {
  25. /**
  26. * Generate a version 1 UUID from a host ID, sequence number, and the current time.
  27. *
  28. * @param int|string|null $node A 48-bit number representing the hardware address
  29. * This number may be represented as an integer or a hexadecimal string.
  30. * @param int|null $clockSeq A 14-bit number used to help avoid duplicates that
  31. * could arise when the clock is set backwards in time or if the node ID
  32. * changes.
  33. * @return UuidInterface
  34. * @throws UnsatisfiedDependencyException if called on a 32-bit system and
  35. * `Moontoast\Math\BigNumber` is not present
  36. * @throws InvalidArgumentException
  37. * @throws Exception if it was not possible to gather sufficient entropy
  38. */
  39. public function uuid1($node = null, $clockSeq = null);
  40. /**
  41. * Generate a version 3 UUID based on the MD5 hash of a namespace identifier
  42. * (which is a UUID) and a name (which is a string).
  43. *
  44. * @param string|UuidInterface $ns The UUID namespace in which to create the named UUID
  45. * @param string $name The name to create a UUID for
  46. * @return UuidInterface
  47. * @throws InvalidUuidStringException
  48. */
  49. public function uuid3($ns, $name);
  50. /**
  51. * Generate a version 4 (random) UUID.
  52. *
  53. * @return UuidInterface
  54. * @throws UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present
  55. * @throws InvalidArgumentException
  56. * @throws Exception
  57. */
  58. public function uuid4();
  59. /**
  60. * Generate a version 5 UUID based on the SHA-1 hash of a namespace
  61. * identifier (which is a UUID) and a name (which is a string).
  62. *
  63. * @param string|UuidInterface $ns The UUID namespace in which to create the named UUID
  64. * @param string $name The name to create a UUID for
  65. * @return UuidInterface
  66. * @throws InvalidUuidStringException
  67. */
  68. public function uuid5($ns, $name);
  69. /**
  70. * Creates a UUID from a byte string.
  71. *
  72. * @param string $bytes A 16-byte string representation of a UUID
  73. * @return UuidInterface
  74. * @throws InvalidUuidStringException
  75. * @throws InvalidArgumentException if string has not 16 characters
  76. */
  77. public function fromBytes($bytes);
  78. /**
  79. * Creates a UUID from the string standard representation
  80. *
  81. * @param string $uuid A string representation of a UUID
  82. * @return UuidInterface
  83. * @throws InvalidUuidStringException
  84. */
  85. public function fromString($uuid);
  86. /**
  87. * Creates a `Uuid` from an integer representation
  88. *
  89. * The integer representation may be a real integer, a string integer, or
  90. * an integer representation supported by a configured number converter.
  91. *
  92. * @param mixed $integer The integer to use when creating a `Uuid` from an
  93. * integer; may be of any type understood by the configured number converter
  94. * @return UuidInterface
  95. * @throws UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present
  96. * @throws InvalidUuidStringException
  97. */
  98. public function fromInteger($integer);
  99. }