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.     #[ReturnTypeWillChange]
  193.     public function jsonSerialize()
  194.     {
  195.         return $this->toString();
  196.     }
  197.     /**
  198.      * Converts this UUID object to a string when the object is serialized
  199.      * with `serialize()`
  200.      *
  201.      * @return string
  202.      * @link http://php.net/manual/en/class.serializable.php
  203.      */
  204.     #[ReturnTypeWillChange]
  205.     public function serialize()
  206.     {
  207.         return $this->toString();
  208.     }
  209.     /**
  210.      * @return array{string: string}
  211.      */
  212.     #[ReturnTypeWillChange]
  213.     public function __serialize()
  214.     {
  215.         return ['string' => $this->toString()];
  216.     }
  217.     /**
  218.      * Re-constructs the object from its serialized form.
  219.      *
  220.      * @param string $serialized
  221.      * @link http://php.net/manual/en/class.serializable.php
  222.      * @throws InvalidUuidStringException
  223.      */
  224.     #[ReturnTypeWillChange]
  225.     public function unserialize($serialized)
  226.     {
  227.         $uuid self::fromString($serialized);
  228.         $this->codec $uuid->codec;
  229.         $this->converter $uuid->converter;
  230.         $this->fields $uuid->fields;
  231.     }
  232.     /**
  233.      * @param array{string: string} $serialized
  234.      * @return void
  235.      * @throws InvalidUuidStringException
  236.      */
  237.     #[ReturnTypeWillChange]
  238.     public function __unserialize(array $serialized)
  239.     {
  240.         // @codeCoverageIgnoreStart
  241.         if (!isset($serialized['string'])) {
  242.             throw new InvalidUuidStringException();
  243.         }
  244.         // @codeCoverageIgnoreEnd
  245.         $this->unserialize($serialized['string']);
  246.     }
  247.     public function compareTo(UuidInterface $other)
  248.     {
  249.         if ($this->getMostSignificantBitsHex() < $other->getMostSignificantBitsHex()) {
  250.             return -1;
  251.         }
  252.         if ($this->getMostSignificantBitsHex() > $other->getMostSignificantBitsHex()) {
  253.             return 1;
  254.         }
  255.         if ($this->getLeastSignificantBitsHex() < $other->getLeastSignificantBitsHex()) {
  256.             return -1;
  257.         }
  258.         if ($this->getLeastSignificantBitsHex() > $other->getLeastSignificantBitsHex()) {
  259.             return 1;
  260.         }
  261.         return 0;
  262.     }
  263.     public function equals($other)
  264.     {
  265.         if (!$other instanceof UuidInterface) {
  266.             return false;
  267.         }
  268.         return $this->compareTo($other) == 0;
  269.     }
  270.     public function getBytes()
  271.     {
  272.         return $this->codec->encodeBinary($this);
  273.     }
  274.     /**
  275.      * Returns the high field of the clock sequence multiplexed with the variant
  276.      * (bits 65-72 of the UUID).
  277.      *
  278.      * @return int Unsigned 8-bit integer value of clock_seq_hi_and_reserved
  279.      */
  280.     public function getClockSeqHiAndReserved()
  281.     {
  282.         return hexdec($this->getClockSeqHiAndReservedHex());
  283.     }
  284.     public function getClockSeqHiAndReservedHex()
  285.     {
  286.         return $this->fields['clock_seq_hi_and_reserved'];
  287.     }
  288.     /**
  289.      * Returns the low field of the clock sequence (bits 73-80 of the UUID).
  290.      *
  291.      * @return int Unsigned 8-bit integer value of clock_seq_low
  292.      */
  293.     public function getClockSeqLow()
  294.     {
  295.         return hexdec($this->getClockSeqLowHex());
  296.     }
  297.     public function getClockSeqLowHex()
  298.     {
  299.         return $this->fields['clock_seq_low'];
  300.     }
  301.     /**
  302.      * Returns the clock sequence value associated with this UUID.
  303.      *
  304.      * For UUID version 1, the clock sequence is used to help avoid
  305.      * duplicates that could arise when the clock is set backwards in time
  306.      * or if the node ID changes.
  307.      *
  308.      * For UUID version 3 or 5, the clock sequence is a 14-bit value
  309.      * constructed from a name as described in RFC 4122, Section 4.3.
  310.      *
  311.      * For UUID version 4, clock sequence is a randomly or pseudo-randomly
  312.      * generated 14-bit value as described in RFC 4122, Section 4.4.
  313.      *
  314.      * @return int Unsigned 14-bit integer value of clock sequence
  315.      * @link http://tools.ietf.org/html/rfc4122#section-4.1.5
  316.      */
  317.     public function getClockSequence()
  318.     {
  319.         return ($this->getClockSeqHiAndReserved() & 0x3f) << $this->getClockSeqLow();
  320.     }
  321.     public function getClockSequenceHex()
  322.     {
  323.         return sprintf('%04x'$this->getClockSequence());
  324.     }
  325.     public function getNumberConverter()
  326.     {
  327.         return $this->converter;
  328.     }
  329.     /**
  330.      * @inheritdoc
  331.      */
  332.     public function getDateTime()
  333.     {
  334.         if ($this->getVersion() != 1) {
  335.             throw new UnsupportedOperationException('Not a time-based UUID');
  336.         }
  337.         $unixTimeNanoseconds $this->getTimestamp() - 0x01b21dd213814000;
  338.         $unixTime = ($unixTimeNanoseconds $unixTimeNanoseconds 1e7) / 1e7;
  339.         return new DateTime("@{$unixTime}");
  340.     }
  341.     /**
  342.      * Returns an array of the fields of this UUID, with keys named according
  343.      * to the RFC 4122 names for the fields.
  344.      *
  345.      * * **time_low**: The low field of the timestamp, an unsigned 32-bit integer
  346.      * * **time_mid**: The middle field of the timestamp, an unsigned 16-bit integer
  347.      * * **time_hi_and_version**: The high field of the timestamp multiplexed with
  348.      *   the version number, an unsigned 16-bit integer
  349.      * * **clock_seq_hi_and_reserved**: The high field of the clock sequence
  350.      *   multiplexed with the variant, an unsigned 8-bit integer
  351.      * * **clock_seq_low**: The low field of the clock sequence, an unsigned
  352.      *   8-bit integer
  353.      * * **node**: The spatially unique node identifier, an unsigned 48-bit
  354.      *   integer
  355.      *
  356.      * @return array The UUID fields represented as integer values
  357.      * @link http://tools.ietf.org/html/rfc4122#section-4.1.2
  358.      */
  359.     public function getFields()
  360.     {
  361.         return [
  362.             'time_low' => $this->getTimeLow(),
  363.             'time_mid' => $this->getTimeMid(),
  364.             'time_hi_and_version' => $this->getTimeHiAndVersion(),
  365.             'clock_seq_hi_and_reserved' => $this->getClockSeqHiAndReserved(),
  366.             'clock_seq_low' => $this->getClockSeqLow(),
  367.             'node' => $this->getNode(),
  368.         ];
  369.     }
  370.     public function getFieldsHex()
  371.     {
  372.         return $this->fields;
  373.     }
  374.     public function getHex()
  375.     {
  376.         return str_replace('-'''$this->toString());
  377.     }
  378.     /**
  379.      * @inheritdoc
  380.      */
  381.     public function getInteger()
  382.     {
  383.         return $this->converter->fromHex($this->getHex());
  384.     }
  385.     /**
  386.      * Returns the least significant 64 bits of this UUID's 128 bit value.
  387.      *
  388.      * @return mixed Converted representation of the unsigned 64-bit integer value
  389.      * @throws UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present
  390.      */
  391.     public function getLeastSignificantBits()
  392.     {
  393.         return $this->converter->fromHex($this->getLeastSignificantBitsHex());
  394.     }
  395.     public function getLeastSignificantBitsHex()
  396.     {
  397.         return sprintf(
  398.             '%02s%02s%012s',
  399.             $this->fields['clock_seq_hi_and_reserved'],
  400.             $this->fields['clock_seq_low'],
  401.             $this->fields['node']
  402.         );
  403.     }
  404.     /**
  405.      * Returns the most significant 64 bits of this UUID's 128 bit value.
  406.      *
  407.      * @return mixed Converted representation of the unsigned 64-bit integer value
  408.      * @throws UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present
  409.      */
  410.     public function getMostSignificantBits()
  411.     {
  412.         return $this->converter->fromHex($this->getMostSignificantBitsHex());
  413.     }
  414.     public function getMostSignificantBitsHex()
  415.     {
  416.         return sprintf(
  417.             '%08s%04s%04s',
  418.             $this->fields['time_low'],
  419.             $this->fields['time_mid'],
  420.             $this->fields['time_hi_and_version']
  421.         );
  422.     }
  423.     /**
  424.      * Returns the node value associated with this UUID
  425.      *
  426.      * For UUID version 1, the node field consists of an IEEE 802 MAC
  427.      * address, usually the host address. For systems with multiple IEEE
  428.      * 802 addresses, any available one can be used. The lowest addressed
  429.      * octet (octet number 10) contains the global/local bit and the
  430.      * unicast/multicast bit, and is the first octet of the address
  431.      * transmitted on an 802.3 LAN.
  432.      *
  433.      * For systems with no IEEE address, a randomly or pseudo-randomly
  434.      * generated value may be used; see RFC 4122, Section 4.5. The
  435.      * multicast bit must be set in such addresses, in order that they
  436.      * will never conflict with addresses obtained from network cards.
  437.      *
  438.      * For UUID version 3 or 5, the node field is a 48-bit value constructed
  439.      * from a name as described in RFC 4122, Section 4.3.
  440.      *
  441.      * For UUID version 4, the node field is a randomly or pseudo-randomly
  442.      * generated 48-bit value as described in RFC 4122, Section 4.4.
  443.      *
  444.      * @return int Unsigned 48-bit integer value of node
  445.      * @link http://tools.ietf.org/html/rfc4122#section-4.1.6
  446.      */
  447.     public function getNode()
  448.     {
  449.         return hexdec($this->getNodeHex());
  450.     }
  451.     public function getNodeHex()
  452.     {
  453.         return $this->fields['node'];
  454.     }
  455.     /**
  456.      * Returns the high field of the timestamp multiplexed with the version
  457.      * number (bits 49-64 of the UUID).
  458.      *
  459.      * @return int Unsigned 16-bit integer value of time_hi_and_version
  460.      */
  461.     public function getTimeHiAndVersion()
  462.     {
  463.         return hexdec($this->getTimeHiAndVersionHex());
  464.     }
  465.     public function getTimeHiAndVersionHex()
  466.     {
  467.         return $this->fields['time_hi_and_version'];
  468.     }
  469.     /**
  470.      * Returns the low field of the timestamp (the first 32 bits of the UUID).
  471.      *
  472.      * @return int Unsigned 32-bit integer value of time_low
  473.      */
  474.     public function getTimeLow()
  475.     {
  476.         return hexdec($this->getTimeLowHex());
  477.     }
  478.     public function getTimeLowHex()
  479.     {
  480.         return $this->fields['time_low'];
  481.     }
  482.     /**
  483.      * Returns the middle field of the timestamp (bits 33-48 of the UUID).
  484.      *
  485.      * @return int Unsigned 16-bit integer value of time_mid
  486.      */
  487.     public function getTimeMid()
  488.     {
  489.         return hexdec($this->getTimeMidHex());
  490.     }
  491.     public function getTimeMidHex()
  492.     {
  493.         return $this->fields['time_mid'];
  494.     }
  495.     /**
  496.      * Returns the timestamp value associated with this UUID.
  497.      *
  498.      * The 60 bit timestamp value is constructed from the time_low,
  499.      * time_mid, and time_hi fields of this UUID. The resulting
  500.      * timestamp is measured in 100-nanosecond units since midnight,
  501.      * October 15, 1582 UTC.
  502.      *
  503.      * The timestamp value is only meaningful in a time-based UUID, which
  504.      * has version type 1. If this UUID is not a time-based UUID then
  505.      * this method throws UnsupportedOperationException.
  506.      *
  507.      * @return int Unsigned 60-bit integer value of the timestamp
  508.      * @throws UnsupportedOperationException If this UUID is not a version 1 UUID
  509.      * @link http://tools.ietf.org/html/rfc4122#section-4.1.4
  510.      */
  511.     public function getTimestamp()
  512.     {
  513.         if ($this->getVersion() != 1) {
  514.             throw new UnsupportedOperationException('Not a time-based UUID');
  515.         }
  516.         return hexdec($this->getTimestampHex());
  517.     }
  518.     /**
  519.      * @inheritdoc
  520.      */
  521.     public function getTimestampHex()
  522.     {
  523.         if ($this->getVersion() != 1) {
  524.             throw new UnsupportedOperationException('Not a time-based UUID');
  525.         }
  526.         return sprintf(
  527.             '%03x%04s%08s',
  528.             ($this->getTimeHiAndVersion() & 0x0fff),
  529.             $this->fields['time_mid'],
  530.             $this->fields['time_low']
  531.         );
  532.     }
  533.     public function getUrn()
  534.     {
  535.         return 'urn:uuid:' $this->toString();
  536.     }
  537.     public function getVariant()
  538.     {
  539.         $clockSeq $this->getClockSeqHiAndReserved();
  540.         if (=== ($clockSeq 0x80)) {
  541.             return self::RESERVED_NCS;
  542.         }
  543.         if (=== ($clockSeq 0x40)) {
  544.             return self::RFC_4122;
  545.         }
  546.         if (=== ($clockSeq 0x20)) {
  547.             return self::RESERVED_MICROSOFT;
  548.         }
  549.         return self::RESERVED_FUTURE;
  550.     }
  551.     public function getVersion()
  552.     {
  553.         if ($this->getVariant() == self::RFC_4122) {
  554.             return (int) (($this->getTimeHiAndVersion() >> 12) & 0x0f);
  555.         }
  556.         return null;
  557.     }
  558.     public function toString()
  559.     {
  560.         return $this->codec->encode($this);
  561.     }
  562.     /**
  563.      * Returns the currently set factory used to create UUIDs.
  564.      *
  565.      * @return UuidFactoryInterface
  566.      */
  567.     public static function getFactory()
  568.     {
  569.         if (!self::$factory) {
  570.             self::$factory = new UuidFactory();
  571.         }
  572.         return self::$factory;
  573.     }
  574.     /**
  575.      * Sets the factory used to create UUIDs.
  576.      *
  577.      * @param UuidFactoryInterface $factory
  578.      */
  579.     public static function setFactory(UuidFactoryInterface $factory)
  580.     {
  581.         self::$factory $factory;
  582.     }
  583.     /**
  584.      * Creates a UUID from a byte string.
  585.      *
  586.      * @param string $bytes
  587.      * @return UuidInterface
  588.      * @throws InvalidUuidStringException
  589.      * @throws InvalidArgumentException
  590.      */
  591.     public static function fromBytes($bytes)
  592.     {
  593.         return self::getFactory()->fromBytes($bytes);
  594.     }
  595.     /**
  596.      * Creates a UUID from the string standard representation.
  597.      *
  598.      * @param string $name A string that specifies a UUID
  599.      * @return UuidInterface
  600.      * @throws InvalidUuidStringException
  601.      */
  602.     public static function fromString($name)
  603.     {
  604.         return self::getFactory()->fromString($name);
  605.     }
  606.     /**
  607.      * Creates a UUID from a 128-bit integer string.
  608.      *
  609.      * @param string $integer String representation of 128-bit integer
  610.      * @return UuidInterface
  611.      * @throws UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present
  612.      * @throws InvalidUuidStringException
  613.      */
  614.     public static function fromInteger($integer)
  615.     {
  616.         return self::getFactory()->fromInteger($integer);
  617.     }
  618.     /**
  619.      * Check if a string is a valid UUID.
  620.      *
  621.      * @param string $uuid The string UUID to test
  622.      * @return boolean
  623.      */
  624.     public static function isValid($uuid)
  625.     {
  626.         $uuid str_replace(['urn:''uuid:''URN:''UUID:''{''}'], ''$uuid);
  627.         if ($uuid == self::NIL) {
  628.             return true;
  629.         }
  630.         if (!preg_match('/' self::VALID_PATTERN '/D'$uuid)) {
  631.             return false;
  632.         }
  633.         return true;
  634.     }
  635.     /**
  636.      * Generate a version 1 UUID from a host ID, sequence number, and the current time.
  637.      *
  638.      * @param int|string $node A 48-bit number representing the hardware address
  639.      *     This number may be represented as an integer or a hexadecimal string.
  640.      * @param int $clockSeq A 14-bit number used to help avoid duplicates that
  641.      *     could arise when the clock is set backwards in time or if the node ID
  642.      *     changes.
  643.      * @return UuidInterface
  644.      * @throws UnsatisfiedDependencyException if called on a 32-bit system and
  645.      *     `Moontoast\Math\BigNumber` is not present
  646.      * @throws InvalidArgumentException
  647.      * @throws Exception if it was not possible to gather sufficient entropy
  648.      */
  649.     public static function uuid1($node null$clockSeq null)
  650.     {
  651.         return self::getFactory()->uuid1($node$clockSeq);
  652.     }
  653.     /**
  654.      * Generate a version 3 UUID based on the MD5 hash of a namespace identifier
  655.      * (which is a UUID) and a name (which is a string).
  656.      *
  657.      * @param string|UuidInterface $ns The UUID namespace in which to create the named UUID
  658.      * @param string $name The name to create a UUID for
  659.      * @return UuidInterface
  660.      * @throws InvalidUuidStringException
  661.      */
  662.     public static function uuid3($ns$name)
  663.     {
  664.         return self::getFactory()->uuid3($ns$name);
  665.     }
  666.     /**
  667.      * Generate a version 4 (random) UUID.
  668.      *
  669.      * @return UuidInterface
  670.      * @throws UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present
  671.      * @throws InvalidArgumentException
  672.      * @throws Exception
  673.      */
  674.     public static function uuid4()
  675.     {
  676.         return self::getFactory()->uuid4();
  677.     }
  678.     /**
  679.      * Generate a version 5 UUID based on the SHA-1 hash of a namespace
  680.      * identifier (which is a UUID) and a name (which is a string).
  681.      *
  682.      * @param string|UuidInterface $ns The UUID namespace in which to create the named UUID
  683.      * @param string $name The name to create a UUID for
  684.      * @return UuidInterface
  685.      * @throws InvalidUuidStringException
  686.      */
  687.     public static function uuid5($ns$name)
  688.     {
  689.         return self::getFactory()->uuid5($ns$name);
  690.     }
  691. }