Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. UuidFactory.php

function UuidFactory::uuidFromBytesAndVersion

Returns an RFC 4122 variant Uuid, created from the provided bytes and version

@psalm-pure

Parameters

string $bytes The byte string to convert to a UUID:

int $version The RFC 4122 version to apply to the UUID:

Return value

UuidInterface An instance of UuidInterface, created from the byte string and version

8 calls to UuidFactory::uuidFromBytesAndVersion()
UuidFactory::fromDateTime in vendor/ramsey/uuid/src/UuidFactory.php
Creates a UUID from a DateTimeInterface instance
UuidFactory::uuid1 in vendor/ramsey/uuid/src/UuidFactory.php
@inheritDoc
UuidFactory::uuid2 in vendor/ramsey/uuid/src/UuidFactory.php
Returns a version 2 (DCE Security) UUID from a local domain, local identifier, host ID, clock sequence, and the current time
UuidFactory::uuid4 in vendor/ramsey/uuid/src/UuidFactory.php
Returns a version 4 (random) UUID
UuidFactory::uuid6 in vendor/ramsey/uuid/src/UuidFactory.php
Returns a version 6 (reordered time) UUID from a host ID, sequence number, and the current time

... See full list

File

vendor/ramsey/uuid/src/UuidFactory.php, line 491

Class

UuidFactory

Namespace

Ramsey\Uuid

Code

private function uuidFromBytesAndVersion(string $bytes, int $version) : UuidInterface {
    
    /** @var array $unpackedTime */
    $unpackedTime = unpack('n*', substr($bytes, 6, 2));
    $timeHi = (int) $unpackedTime[1];
    $timeHiAndVersion = pack('n*', BinaryUtils::applyVersion($timeHi, $version));
    
    /** @var array $unpackedClockSeq */
    $unpackedClockSeq = unpack('n*', substr($bytes, 8, 2));
    $clockSeqHi = (int) $unpackedClockSeq[1];
    $clockSeqHiAndReserved = pack('n*', BinaryUtils::applyVariant($clockSeqHi));
    $bytes = substr_replace($bytes, $timeHiAndVersion, 6, 2);
    $bytes = substr_replace($bytes, $clockSeqHiAndReserved, 8, 2);
    if ($this->isDefaultFeatureSet) {
        return LazyUuidFromString::fromBytes($bytes);
    }
    
    /** @psalm-suppress ImpureVariable */
    return $this->uuid($bytes);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal