No Description

functions.php 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. namespace Ramsey\Uuid;
  12. use Exception;
  13. use InvalidArgumentException;
  14. use Ramsey\Uuid\Exception\InvalidUuidStringException;
  15. use Ramsey\Uuid\Exception\UnsatisfiedDependencyException;
  16. /**
  17. * Generate a version 1 UUID from a host ID, sequence number, and the current time.
  18. *
  19. * @param int|string|null $node A 48-bit number representing the hardware address
  20. * This number may be represented as an integer or a hexadecimal string.
  21. * @param int|null $clockSeq A 14-bit number used to help avoid duplicates that
  22. * could arise when the clock is set backwards in time or if the node ID
  23. * changes.
  24. * @return string
  25. * @throws UnsatisfiedDependencyException if called on a 32-bit system and
  26. * `Moontoast\Math\BigNumber` is not present
  27. * @throws InvalidArgumentException
  28. * @throws Exception if it was not possible to gather sufficient entropy
  29. */
  30. function v1($node = null, $clockSeq = null)
  31. {
  32. return Uuid::uuid1($node, $clockSeq)->toString();
  33. }
  34. /**
  35. * Generate a version 3 UUID based on the MD5 hash of a namespace identifier
  36. * (which is a UUID) and a name (which is a string).
  37. *
  38. * @param string|UuidInterface $ns The UUID namespace in which to create the named UUID
  39. * @param string $name The name to create a UUID for
  40. * @return string
  41. * @throws InvalidUuidStringException
  42. */
  43. function v3($ns, $name)
  44. {
  45. return Uuid::uuid3($ns, $name)->toString();
  46. }
  47. /**
  48. * Generate a version 4 (random) UUID.
  49. *
  50. * @return string
  51. * @throws UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present
  52. * @throws InvalidArgumentException
  53. * @throws Exception
  54. */
  55. function v4()
  56. {
  57. return Uuid::uuid4()->toString();
  58. }
  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 string
  66. * @throws InvalidUuidStringException
  67. */
  68. function v5($ns, $name)
  69. {
  70. return Uuid::uuid5($ns, $name)->toString();
  71. }