src/Generator/DefaultTimeGenerator.php
public function generate($node = null, $clockSeq = null)
    {
        $node = $this->getValidNode($node);

        if ($clockSeq === null) {
            // Not using "stable storage"; see RFC 4122, Section 4.2.1.1
            $clockSeq = random_int(0, 0x3fff);
        }

        // Create a 60-bit time value as a count of 100-nanosecond intervals
        // since 00:00:00.00, 15 October 1582
        $timeOfDay = $this->timeProvider->currentTime();
        $uuidTime = $this->timeConverter->calculateTime((string) $timeOfDay['sec'], (string) $timeOfDay['usec']);

        $timeHi = BinaryUtils::applyVersion($uuidTime['hi'], 1);
        $clockSeqHi = BinaryUtils::applyVariant($clockSeq >> 8);

        $hex = vsprintf(
            '%08s%04s%04s%02s%02s%012s',
            [
                $uuidTime['low'],
                $uuidTime['mid'],
                sprintf('%04x', $timeHi),
                sprintf('%02x', $clockSeqHi),
                sprintf('%02x', $clockSeq & 0xff),
                $node,
            ]
        );

        return hex2bin($hex);
    }
public function generate($node = null, $clockSeq = null)
    {
        $node = $this->getValidNode($node);

        if ($clockSeq === null) {
            // Not using "stable storage"; see RFC 4122, Section 4.2.1.1
            $clockSeq = random_int(0, 0x3fff);
        }

        // Create a 60-bit time value as a count of 100-nanosecond intervals
        // since 00:00:00.00, 15 October 1582
        $timeOfDay = $this->timeProvider->currentTime();
        $uuidTime = $this->timeConverter->calculateTime((string) $timeOfDay['sec'], (string) $timeOfDay['usec']);

        $timeHi = BinaryUtils::applyVersion($uuidTime['hi'], 1);
        $clockSeqHi = BinaryUtils::applyVariant($clockSeq >> 8);

        $hex = vsprintf(
            '%08s%04s%04s%02s%02s%012s',
            [
                $uuidTime['low'],
                $uuidTime['mid'],
                sprintf('%04x', $timeHi),
                sprintf('%02x', $clockSeqHi),
                sprintf('%02x', $clockSeq & 0xff),
                $node,
            ]
        );

        return hex2bin($hex);
    }
public function generate ( $ node = null , $ clockSeq = null ) { $ node = $ this -> getValidNode ( $ node ) ; if ( $ clockSeq === null ) { // Not using "stable storage"; see RFC 4122, Section 4.2.1.1 $ clockSeq = random_int ( 0 , 0x3fff ) ; } // Create a 60-bit time value as a count of 100-nanosecond intervals // since 00:00:00.00, 15 October 1582 $ timeOfDay = $ this -> timeProvider -> currentTime ( ) ; $ uuidTime = $ this -> timeConverter -> calculateTime ( ( string ) $ timeOfDay [ 'sec' ] , ( string ) $ timeOfDay [ 'usec' ] ) ; $ timeHi = BinaryUtils :: applyVersion ( $ uuidTime [ 'hi' ] , 1 ) ; $ clockSeqHi = BinaryUtils :: applyVariant ( $ clockSeq >> 8 ) ; $ hex = vsprintf ( '%08s%04s%04s%02s%02s%012s' , [ $ uuidTime [ 'low' ] , $ uuidTime [ 'mid' ] , sprintf ( '%04x' , $ timeHi ) , sprintf ( '%02x' , $ clockSeqHi ) , sprintf ( '%02x' , $ clockSeq & 0xff ) , $ node , ] ) ; return hex2bin ( $ hex ) ; }
Generate a version 1 UUID from a host ID, sequence number, and the current time

If $node is not given, we will attempt to obtain the local hardware
address. If $clockSeq is given, it is used as the sequence number;
otherwise a random 14-bit sequence number is chosen.

@param int|string $node A 48-bit number representing the hardware address
This number may be represented as an integer or a hexadecimal string.
@param int $clockSeq A 14-bit number used to help avoid duplicates that
could arise when the clock is set backwards in time or if the node ID
changes.
@return string A binary string
@throws \Ramsey\Uuid\Exception\UnsatisfiedDependencyException if called on a 32-bit system and
`Moontoast\Math\BigNumber` is not present
@throws \InvalidArgumentException
@throws \Exception if it was not possible to gather sufficient entropy
Generate a version 1 UUID from a host ID sequence number and the current time