vendor/ramsey/uuid/src/Uuid.php line 43

Open in your IDE?
  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 DateTime;
  16. use Exception;
  17. use InvalidArgumentException;
  18. use Ramsey\Uuid\Converter\NumberConverterInterface;
  19. use Ramsey\Uuid\Codec\CodecInterface;
  20. use Ramsey\Uuid\Exception\InvalidUuidStringException;
  21. use Ramsey\Uuid\Exception\UnsatisfiedDependencyException;
  22. use Ramsey\Uuid\Exception\UnsupportedOperationException;
  23. use ReturnTypeWillChange;
  24. /**
  25.  * Represents a universally unique identifier (UUID), according to RFC 4122.
  26.  *
  27.  * This class provides immutable UUID objects (the Uuid class) and the static
  28.  * methods `uuid1()`, `uuid3()`, `uuid4()`, and `uuid5()` for generating version
  29.  * 1, 3, 4, and 5 UUIDs as specified in RFC 4122.
  30.  *
  31.  * If all you want is a unique ID, you should probably call `uuid1()` or `uuid4()`.
  32.  * Note that `uuid1()` may compromise privacy since it creates a UUID containing
  33.  * the computer’s network address. `uuid4()` creates a random UUID.
  34.  *
  35.  * @link http://tools.ietf.org/html/rfc4122
  36.  * @link http://en.wikipedia.org/wiki/Universally_unique_identifier
  37.  * @link http://docs.python.org/3/library/uuid.html
  38.  * @link http://docs.oracle.com/javase/6/docs/api/java/util/UUID.html
  39.  */
  40. class Uuid implements UuidInterface
  41. {
  42.     /**
  43.      * When this namespace is specified, the name string is a fully-qualified domain name.
  44.      * @link http://tools.ietf.org/html/rfc4122#appendix-C
  45.      */
  46.     const NAMESPACE_DNS '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
  47.     /**
  48.      * When this namespace is specified, the name string is a URL.
  49.      * @link http://tools.ietf.org/html/rfc4122#appendix-C
  50.      */
  51.     const NAMESPACE_URL '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
  52.     /**
  53.      * When this namespace is specified, the name string is an ISO OID.
  54.      * @link http://tools.ietf.org/html/rfc4122#appendix-C
  55.      */
  56.     const NAMESPACE_OID '6ba7b812-9dad-11d1-80b4-00c04fd430c8';
  57.     /**
  58.      * When this namespace is specified, the name string is an X.500 DN in DER or a text output format.
  59.      * @link http://tools.ietf.org/html/rfc4122#appendix-C
  60.      */
  61.     const NAMESPACE_X500 '6ba7b814-9dad-11d1-80b4-00c04fd430c8';
  62.     /**
  63.      * The nil UUID is special form of UUID that is specified to have all 128 bits set to zero.
  64.      * @link http://tools.ietf.org/html/rfc4122#section-4.1.7
  65.      */
  66.     const NIL '00000000-0000-0000-0000-000000000000';
  67.     /**
  68.      * Reserved for NCS compatibility.
  69.      * @link http://tools.ietf.org/html/rfc4122#section-4.1.1
  70.      */
  71.     const RESERVED_NCS 0;
  72.     /**
  73.      * Specifies the UUID layout given in RFC 4122.
  74.      * @link http://tools.ietf.org/html/rfc4122#section-4.1.1
  75.      */
  76.     const RFC_4122 2;
  77.     /**
  78.      * Reserved for Microsoft compatibility.
  79.      * @link http://tools.ietf.org/html/rfc4122#section-4.1.1
  80.      */
  81.     const RESERVED_MICROSOFT 6;
  82.     /**
  83.      * Reserved for future definition.
  84.      * @link http://tools.ietf.org/html/rfc4122#section-4.1.1
  85.      */
  86.     const RESERVED_FUTURE 7;
  87.     /**
  88.      * Regular expression pattern for matching a valid UUID of any variant.
  89.      */
  90.     const VALID_PATTERN '^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$';
  91.     /**
  92.      * Version 1 (time-based) UUID object constant identifier
  93.      */
  94.     const UUID_TYPE_TIME 1;
  95.     /**
  96.      * Version 2 (identifier-based) UUID object constant identifier
  97.      */
  98.     const UUID_TYPE_IDENTIFIER 2;
  99.     /**
  100.      * Version 3 (name-based and hashed with MD5) UUID object constant identifier
  101.      */
  102.     const UUID_TYPE_HASH_MD5 3;
  103.     /**
  104.      * Version 4 (random) UUID object constant identifier
  105.      */
  106.     const UUID_TYPE_RANDOM 4;
  107.     /**
  108.      * Version 5 (name-based and hashed with SHA1) UUID object constant identifier
  109.      */
  110.     const UUID_TYPE_HASH_SHA1 5;
  111.     /**
  112.      * The factory to use when creating UUIDs.
  113.      * @var UuidFactoryInterface
  114.      */
  115.     private static $factory null;
  116.     /**
  117.      * The codec to use when encoding or decoding UUID strings.
  118.      * @var CodecInterface
  119.      */
  120.     protected $codec;
  121.     /**
  122.      * The fields that make up this UUID.
  123.      *
  124.      * This is initialized to the nil value.
  125.      *
  126.      * @var array
  127.      * @see UuidInterface::getFieldsHex()
  128.      */
  129.     protected $fields = [
  130.         'time_low' => '00000000',
  131.         'time_mid' => '0000',
  132.         'time_hi_and_version' => '0000',
  133.         'clock_seq_hi_and_reserved' => '00',
  134.         'clock_seq_low' => '00',
  135.         'node' => '000000000000',
  136.     ];
  137.     /**
  138.      * The number converter to use for converting hex values to/from integers.
  139.      * @var NumberConverterInterface
  140.      */
  141.     protected $converter;
  142.     /**
  143.      * Creates a universally unique identifier (UUID) from an array of fields.
  144.      *
  145.      * Unless you're making advanced use of this library to generate identifiers
  146.      * that deviate from RFC 4122, you probably do not want to instantiate a
  147.      * UUID directly. Use the static methods, instead:
  148.      *
  149.      * ```
  150.      * use Ramsey\Uuid\Uuid;
  151.      *
  152.      * $timeBasedUuid     = Uuid::uuid1();
  153.      * $namespaceMd5Uuid  = Uuid::uuid3(Uuid::NAMESPACE_URL, 'http://php.net/');
  154.      * $randomUuid        = Uuid::uuid4();
  155.      * $namespaceSha1Uuid = Uuid::uuid5(Uuid::NAMESPACE_URL, 'http://php.net/');
  156.      * ```
  157.      *
  158.      * @param array $fields An array of fields from which to construct a UUID;
  159.      *     see {@see \Ramsey\Uuid\UuidInterface::getFieldsHex()} for array structure.
  160.      * @param NumberConverterInterface $converter The number converter to use
  161.      *     for converting hex values to/from integers.
  162.      * @param CodecInterface $codec The codec to use when encoding or decoding
  163.      *     UUID strings.
  164.      */
  165.     public function __construct(
  166.         array $fields,
  167.         NumberConverterInterface $converter,
  168.         CodecInterface $codec
  169.     ) {
  170.         $this->fields $fields;
  171.         $this->codec $codec;
  172.         $this->converter $converter;
  173.     }
  174.     /**
  175.      * Converts this UUID object to a string when the object is used in any
  176.      * string context.
  177.      *
  178.      * @return string
  179.      * @link http://www.php.net/manual/en/language.oop5.magic.php#object.tostring
  180.      */
  181.     public function __toString()
  182.     {
  183.         return $this->toString();
  184.     }
  185.     /**
  186.      * Converts this UUID object to a string when the object is serialized
  187.      * with `json_encode()`
  188.      *
  189.      * @return string
  190.      * @link http://php.net/manual/en/class.jsonserializable.php
  191.      */
  192.     public function jsonSerialize()
  193.     {
  194.         return $this->toString();
  195.     }
  196.     /**
  197.      * Converts this UUID object to a string when the object is serialized
  198.      * with `serialize()`
  199.      *
  200.      * @return string
  201.      * @link http://php.net/manual/en/class.serializable.php
  202.      */
  203.     #[ReturnTypeWillChange]
  204.     public function serialize()
  205.     {
  206.         return $this->toString();
  207.     }
  208.     /**
  209.      * @return array{string: string}
  210.      */
  211.     #[ReturnTypeWillChange]
  212.     public function __serialize()
  213.     {
  214.         return ['string' => $this->toString()];
  215.     }
  216.     /**
  217.      * Re-constructs the object from its serialized form.
  218.      *
  219.      * @param string $serialized
  220.      * @link http://php.net/manual/en/class.serializable.php
  221.      * @throws InvalidUuidStringException
  222.      */
  223.     #[ReturnTypeWillChange]
  224.     public function unserialize($serialized)
  225.     {
  226.         $uuid self::fromString($serialized);
  227.         $this->codec $uuid->codec;
  228.         $this->converter $uuid->converter;
  229.         $this->fields $uuid->fields;
  230.     }
  231.     /**
  232.      * @param array{string: string} $serialized
  233.      * @return void
  234.      * @throws InvalidUuidStringException
  235.      */
  236.     #[ReturnTypeWillChange]
  237.     public function __unserialize(array $serialized)
  238.     {
  239.         // @codeCoverageIgnoreStart
  240.         if (!isset($serialized['string'])) {
  241.             throw new InvalidUuidStringException();
  242.         }
  243.         // @codeCoverageIgnoreEnd
  244.         $this->unserialize($serialized['string']);
  245.     }
  246.     public function compareTo(UuidInterface $other)
  247.     {
  248.         if ($this->getMostSignificantBitsHex() < $other->getMostSignificantBitsHex()) {
  249.             return -1;
  250.         }
  251.         if ($this->getMostSignificantBitsHex() > $other->getMostSignificantBitsHex()) {
  252.             return 1;
  253.         }
  254.         if ($this->getLeastSignificantBitsHex() < $other->getLeastSignificantBitsHex()) {
  255.             return -1;
  256.         }
  257.         if ($this->getLeastSignificantBitsHex() > $other->getLeastSignificantBitsHex()) {
  258.             return 1;
  259.         }
  260.         return 0;
  261.     }
  262.     public function equals($other)
  263.     {
  264.         if (!$other instanceof UuidInterface) {
  265.             return false;
  266.         }
  267.         return $this->compareTo($other) == 0;
  268.     }
  269.     public function getBytes()
  270.     {
  271.         return $this->codec->encodeBinary($this);
  272.     }
  273.     /**
  274.      * Returns the high field of the clock sequence multiplexed with the variant
  275.      * (bits 65-72 of the UUID).
  276.      *
  277.      * @return int Unsigned 8-bit integer value of clock_seq_hi_and_reserved
  278.      */
  279.     public function getClockSeqHiAndReserved()
  280.     {
  281.         return hexdec($this->getClockSeqHiAndReservedHex());
  282.     }
  283.     public function getClockSeqHiAndReservedHex()
  284.     {
  285.         return $this->fields['clock_seq_hi_and_reserved'];
  286.     }
  287.     /**
  288.      * Returns the low field of the clock sequence (bits 73-80 of the UUID).
  289.      *
  290.      * @return int Unsigned 8-bit integer value of clock_seq_low
  291.      */
  292.     public function getClockSeqLow()
  293.     {
  294.         return hexdec($this->getClockSeqLowHex());
  295.     }
  296.     public function getClockSeqLowHex()
  297.     {
  298.         return $this->fields['clock_seq_low'];
  299.     }
  300.     /**
  301.      * Returns the clock sequence value associated with this UUID.
  302.      *
  303.      * For UUID version 1, the clock sequence is used to help avoid
  304.      * duplicates that could arise when the clock is set backwards in time
  305.      * or if the node ID changes.
  306.      *
  307.      * For UUID version 3 or 5, the clock sequence is a 14-bit value
  308.      * constructed from a name as described in RFC 4122, Section 4.3.
  309.      *
  310.      * For UUID version 4, clock sequence is a randomly or pseudo-randomly
  311.      * generated 14-bit value as described in RFC 4122, Section 4.4.
  312.      *
  313.      * @return int Unsigned 14-bit integer value of clock sequence
  314.      * @link http://tools.ietf.org/html/rfc4122#section-4.1.5
  315.      */
  316.     public function getClockSequence()
  317.     {
  318.         return ($this->getClockSeqHiAndReserved() & 0x3f) << $this->getClockSeqLow();
  319.     }
  320.     public function getClockSequenceHex()
  321.     {
  322.         return sprintf('%04x'$this->getClockSequence());
  323.     }
  324.     public function getNumberConverter()
  325.     {
  326.         return $this->converter;
  327.     }
  328.     /**
  329.      * @inheritdoc
  330.      */
  331.     public function getDateTime()
  332.     {
  333.         if ($this->getVersion() != 1) {
  334.             throw new UnsupportedOperationException('Not a time-based UUID');
  335.         }
  336.         $unixTimeNanoseconds $this->getTimestamp() - 0x01b21dd213814000;
  337.         $unixTime = ($unixTimeNanoseconds $unixTimeNanoseconds 1e7) / 1e7;
  338.         return new DateTime("@{$unixTime}");
  339.     }
  340.     /**
  341.      * Returns an array of the fields of this UUID, with keys named according
  342.      * to the RFC 4122 names for the fields.
  343.      *
  344.      * * **time_low**: The low field of the timestamp, an unsigned 32-bit integer
  345.      * * **time_mid**: The middle field of the timestamp, an unsigned 16-bit integer
  346.      * * **time_hi_and_version**: The high field of the timestamp multiplexed with
  347.      *   the version number, an unsigned 16-bit integer
  348.      * * **clock_seq_hi_and_reserved**: The high field of the clock sequence
  349.      *   multiplexed with the variant, an unsigned 8-bit integer
  350.      * * **clock_seq_low**: The low field of the clock sequence, an unsigned
  351.      *   8-bit integer
  352.      * * **node**: The spatially unique node identifier, an unsigned 48-bit
  353.      *   integer
  354.      *
  355.      * @return array The UUID fields represented as integer values
  356.      * @link http://tools.ietf.org/html/rfc4122#section-4.1.2
  357.      */
  358.     public function getFields()
  359.     {
  360.         return [
  361.             'time_low' => $this->getTimeLow(),
  362.             'time_mid' => $this->getTimeMid(),
  363.             'time_hi_and_version' => $this->getTimeHiAndVersion(),
  364.             'clock_seq_hi_and_reserved' => $this->getClockSeqHiAndReserved(),
  365.             'clock_seq_low' => $this->getClockSeqLow(),
  366.             'node' => $this->getNode(),
  367.         ];
  368.     }
  369.     public function getFieldsHex()
  370.     {
  371.         return $this->fields;
  372.     }
  373.     public function getHex()
  374.     {
  375.         return str_replace('-'''$this->toString());
  376.     }
  377.     /**
  378.      * @inheritdoc
  379.      */
  380.     public function getInteger()
  381.     {
  382.         return $this->converter->fromHex($this->getHex());
  383.     }
  384.     /**
  385.      * Returns the least significant 64 bits of this UUID's 128 bit value.
  386.      *
  387.      * @return mixed Converted representation of the unsigned 64-bit integer value
  388.      * @throws UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present
  389.      */
  390.     public function getLeastSignificantBits()
  391.     {
  392.         return $this->converter->fromHex($this->getLeastSignificantBitsHex());
  393.     }
  394.     public function getLeastSignificantBitsHex()
  395.     {
  396.         return sprintf(
  397.             '%02s%02s%012s',
  398.             $this->fields['clock_seq_hi_and_reserved'],
  399.             $this->fields['clock_seq_low'],
  400.             $this->fields['node']
  401.         );
  402.     }
  403.     /**
  404.      * Returns the most significant 64 bits of this UUID's 128 bit value.
  405.      *
  406.      * @return mixed Converted representation of the unsigned 64-bit integer value
  407.      * @throws UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present
  408.      */
  409.     public function getMostSignificantBits()
  410.     {
  411.         return $this->converter->fromHex($this->getMostSignificantBitsHex());
  412.     }
  413.     public function getMostSignificantBitsHex()
  414.     {
  415.         return sprintf(
  416.             '%08s%04s%04s',
  417.             $this->fields['time_low'],
  418.             $this->fields['time_mid'],
  419.             $this->fields['time_hi_and_version']
  420.         );
  421.     }
  422.     /**
  423.      * Returns the node value associated with this UUID
  424.      *
  425.      * For UUID version 1, the node field consists of an IEEE 802 MAC
  426.      * address, usually the host address. For systems with multiple IEEE
  427.      * 802 addresses, any available one can be used. The lowest addressed
  428.      * octet (octet number 10) contains the global/local bit and the
  429.      * unicast/multicast bit, and is the first octet of the address
  430.      * transmitted on an 802.3 LAN.
  431.      *
  432.      * For systems with no IEEE address, a randomly or pseudo-randomly
  433.      * generated value may be used; see RFC 4122, Section 4.5. The
  434.      * multicast bit must be set in such addresses, in order that they
  435.      * will never conflict with addresses obtained from network cards.
  436.      *
  437.      * For UUID version 3 or 5, the node field is a 48-bit value constructed
  438.      * from a name as described in RFC 4122, Section 4.3.
  439.      *
  440.      * For UUID version 4, the node field is a randomly or pseudo-randomly
  441.      * generated 48-bit value as described in RFC 4122, Section 4.4.
  442.      *
  443.      * @return int Unsigned 48-bit integer value of node
  444.      * @link http://tools.ietf.org/html/rfc4122#section-4.1.6
  445.      */
  446.     public function getNode()
  447.     {
  448.         return hexdec($this->getNodeHex());
  449.     }
  450.     public function getNodeHex()
  451.     {
  452.         return $this->fields['node'];
  453.     }
  454.     /**
  455.      * Returns the high field of the timestamp multiplexed with the version
  456.      * number (bits 49-64 of the UUID).
  457.      *
  458.      * @return int Unsigned 16-bit integer value of time_hi_and_version
  459.      */
  460.     public function getTimeHiAndVersion()
  461.     {
  462.         return hexdec($this->getTimeHiAndVersionHex());
  463.     }
  464.     public function getTimeHiAndVersionHex()
  465.     {
  466.         return $this->fields['time_hi_and_version'];
  467.     }
  468.     /**
  469.      * Returns the low field of the timestamp (the first 32 bits of the UUID).
  470.      *
  471.      * @return int Unsigned 32-bit integer value of time_low
  472.      */
  473.     public function getTimeLow()
  474.     {
  475.         return hexdec($this->getTimeLowHex());
  476.     }
  477.     public function getTimeLowHex()
  478.     {
  479.         return $this->fields['time_low'];
  480.     }
  481.     /**
  482.      * Returns the middle field of the timestamp (bits 33-48 of the UUID).
  483.      *
  484.      * @return int Unsigned 16-bit integer value of time_mid
  485.      */
  486.     public function getTimeMid()
  487.     {
  488.         return hexdec($this->getTimeMidHex());
  489.     }
  490.     public function getTimeMidHex()
  491.     {
  492.         return $this->fields['time_mid'];
  493.     }
  494.     /**
  495.      * Returns the timestamp value associated with this UUID.
  496.      *
  497.      * The 60 bit timestamp value is constructed from the time_low,
  498.      * time_mid, and time_hi fields of this UUID. The resulting
  499.      * timestamp is measured in 100-nanosecond units since midnight,
  500.      * October 15, 1582 UTC.
  501.      *
  502.      * The timestamp value is only meaningful in a time-based UUID, which
  503.      * has version type 1. If this UUID is not a time-based UUID then
  504.      * this method throws UnsupportedOperationException.
  505.      *
  506.      * @return int Unsigned 60-bit integer value of the timestamp
  507.      * @throws UnsupportedOperationException If this UUID is not a version 1 UUID
  508.      * @link http://tools.ietf.org/html/rfc4122#section-4.1.4
  509.      */
  510.     public function getTimestamp()
  511.     {
  512.         if ($this->getVersion() != 1) {
  513.             throw new UnsupportedOperationException('Not a time-based UUID');
  514.         }
  515.         return hexdec($this->getTimestampHex());
  516.     }
  517.     /**
  518.      * @inheritdoc
  519.      */
  520.     public function getTimestampHex()
  521.     {
  522.         if ($this->getVersion() != 1) {
  523.             throw new UnsupportedOperationException('Not a time-based UUID');
  524.         }
  525.         return sprintf(
  526.             '%03x%04s%08s',
  527.             ($this->getTimeHiAndVersion() & 0x0fff),
  528.             $this->fields['time_mid'],
  529.             $this->fields['time_low']
  530.         );
  531.     }
  532.     public function getUrn()
  533.     {
  534.         return 'urn:uuid:' $this->toString();
  535.     }
  536.     public function getVariant()
  537.     {
  538.         $clockSeq $this->getClockSeqHiAndReserved();
  539.         if (=== ($clockSeq 0x80)) {
  540.             return self::RESERVED_NCS;
  541.         }
  542.         if (=== ($clockSeq 0x40)) {
  543.             return self::RFC_4122;
  544.         }
  545.         if (=== ($clockSeq 0x20)) {
  546.             return self::RESERVED_MICROSOFT;
  547.         }
  548.         return self::RESERVED_FUTURE;
  549.     }
  550.     public function getVersion()
  551.     {
  552.         if ($this->getVariant() == self::RFC_4122) {
  553.             return (int) (($this->getTimeHiAndVersion() >> 12) & 0x0f);
  554.         }
  555.         return null;
  556.     }
  557.     public function toString()
  558.     {
  559.         return $this->codec->encode($this);
  560.     }
  561.     /**
  562.      * Returns the currently set factory used to create UUIDs.
  563.      *
  564.      * @return UuidFactoryInterface
  565.      */
  566.     public static function getFactory()
  567.     {
  568.         if (!self::$factory) {
  569.             self::$factory = new UuidFactory();
  570.         }
  571.         return self::$factory;
  572.     }
  573.     /**
  574.      * Sets the factory used to create UUIDs.
  575.      *
  576.      * @param UuidFactoryInterface $factory
  577.      */
  578.     public static function setFactory(UuidFactoryInterface $factory)
  579.     {
  580.         self::$factory $factory;
  581.     }
  582.     /**
  583.      * Creates a UUID from a byte string.
  584.      *
  585.      * @param string $bytes
  586.      * @return UuidInterface
  587.      * @throws InvalidUuidStringException
  588.      * @throws InvalidArgumentException
  589.      */
  590.     public static function fromBytes($bytes)
  591.     {
  592.         return self::getFactory()->fromBytes($bytes);
  593.     }
  594.     /**
  595.      * Creates a UUID from the string standard representation.
  596.      *
  597.      * @param string $name A string that specifies a UUID
  598.      * @return UuidInterface
  599.      * @throws InvalidUuidStringException
  600.      */
  601.     public static function fromString($name)
  602.     {
  603.         return self::getFactory()->fromString($name);
  604.     }
  605.     /**
  606.      * Creates a UUID from a 128-bit integer string.
  607.      *
  608.      * @param string $integer String representation of 128-bit integer
  609.      * @return UuidInterface
  610.      * @throws UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present
  611.      * @throws InvalidUuidStringException
  612.      */
  613.     public static function fromInteger($integer)
  614.     {
  615.         return self::getFactory()->fromInteger($integer);
  616.     }
  617.     /**
  618.      * Check if a string is a valid UUID.
  619.      *
  620.      * @param string $uuid The string UUID to test
  621.      * @return boolean
  622.      */
  623.     public static function isValid($uuid)
  624.     {
  625.         $uuid str_replace(['urn:''uuid:''URN:''UUID:''{''}'], ''$uuid);
  626.         if ($uuid == self::NIL) {
  627.             return true;
  628.         }
  629.         if (!preg_match('/' self::VALID_PATTERN '/D'$uuid)) {
  630.             return false;
  631.         }
  632.         return true;
  633.     }
  634.     /**
  635.      * Generate a version 1 UUID from a host ID, sequence number, and the current time.
  636.      *
  637.      * @param int|string $node A 48-bit number representing the hardware address
  638.      *     This number may be represented as an integer or a hexadecimal string.
  639.      * @param int $clockSeq A 14-bit number used to help avoid duplicates that
  640.      *     could arise when the clock is set backwards in time or if the node ID
  641.      *     changes.
  642.      * @return UuidInterface
  643.      * @throws UnsatisfiedDependencyException if called on a 32-bit system and
  644.      *     `Moontoast\Math\BigNumber` is not present
  645.      * @throws InvalidArgumentException
  646.      * @throws Exception if it was not possible to gather sufficient entropy
  647.      */
  648.     public static function uuid1($node null$clockSeq null)
  649.     {
  650.         return self::getFactory()->uuid1($node$clockSeq);
  651.     }
  652.     /**
  653.      * Generate a version 3 UUID based on the MD5 hash of a namespace identifier
  654.      * (which is a UUID) and a name (which is a string).
  655.      *
  656.      * @param string|UuidInterface $ns The UUID namespace in which to create the named UUID
  657.      * @param string $name The name to create a UUID for
  658.      * @return UuidInterface
  659.      * @throws InvalidUuidStringException
  660.      */
  661.     public static function uuid3($ns$name)
  662.     {
  663.         return self::getFactory()->uuid3($ns$name);
  664.     }
  665.     /**
  666.      * Generate a version 4 (random) UUID.
  667.      *
  668.      * @return UuidInterface
  669.      * @throws UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present
  670.      * @throws InvalidArgumentException
  671.      * @throws Exception
  672.      */
  673.     public static function uuid4()
  674.     {
  675.         return self::getFactory()->uuid4();
  676.     }
  677.     /**
  678.      * Generate a version 5 UUID based on the SHA-1 hash of a namespace
  679.      * identifier (which is a UUID) and a name (which is a string).
  680.      *
  681.      * @param string|UuidInterface $ns The UUID namespace in which to create the named UUID
  682.      * @param string $name The name to create a UUID for
  683.      * @return UuidInterface
  684.      * @throws InvalidUuidStringException
  685.      */
  686.     public static function uuid5($ns$name)
  687.     {
  688.         return self::getFactory()->uuid5($ns$name);
  689.     }
  690. }