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

Breadcrumb

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

class UuidV2

DCE Security version, or version 2, UUIDs include local domain identifier, local ID for the specified domain, and node values that are combined into a 128-bit unsigned integer

It is important to note that a version 2 UUID suffers from some loss of fidelity of the timestamp, due to replacing the time_low field with the local identifier. When constructing the timestamp value for date purposes, we replace the local identifier bits with zeros. As a result, the timestamp can be off by a range of 0 to 429.4967295 seconds (or 7 minutes, 9 seconds, and 496730 microseconds).

Astute observers might note this value directly corresponds to 2^32 - 1, or 0xffffffff. The local identifier is 32-bits, and we have set each of these bits to 0, so the maximum range of timestamp drift is 0x00000000 to 0xffffffff (counted in 100-nanosecond intervals).

@link https://publications.opengroup.org/c311 DCE 1.1: Authentication and Security Services @link https://publications.opengroup.org/c706 DCE 1.1: Remote Procedure Call @link https://pubs.opengroup.org/onlinepubs/9696989899/chap5.htm#tagcjh_08_02… DCE 1.1: Auth & Sec, §5.2.1.1 @link https://pubs.opengroup.org/onlinepubs/9696989899/chap11.htm#tagcjh_14_0… DCE 1.1: Auth & Sec, §11.5.1.1 @link https://pubs.opengroup.org/onlinepubs/9629399/apdxa.htm DCE 1.1: RPC, Appendix A @link https://github.com/google/uuid Go package for UUIDs (includes DCE implementation)

@psalm-immutable

Hierarchy

  • class \Ramsey\Uuid\Uuid implements \Ramsey\Uuid\UuidInterface uses \Ramsey\Uuid\DeprecatedUuidMethodsTrait
    • class \Ramsey\Uuid\Rfc4122\UuidV2 extends \Ramsey\Uuid\Uuid implements \Ramsey\Uuid\Rfc4122\UuidInterface uses \Ramsey\Uuid\Rfc4122\TimeTrait

Expanded class hierarchy of UuidV2

2 files declare their use of UuidV2
DceSecurityGeneratorInterface.php in vendor/ramsey/uuid/src/Generator/DceSecurityGeneratorInterface.php
DceSecurityProviderInterface.php in vendor/ramsey/uuid/src/Provider/DceSecurityProviderInterface.php

File

vendor/ramsey/uuid/src/Rfc4122/UuidV2.php, line 53

Namespace

Ramsey\Uuid\Rfc4122
View source
final class UuidV2 extends Uuid implements UuidInterface {
    use TimeTrait;
    
    /**
     * Creates a version 2 (DCE Security) UUID
     *
     * @param Rfc4122FieldsInterface $fields The fields from which to construct a UUID
     * @param NumberConverterInterface $numberConverter The number converter to use
     *     for converting hex values to/from integers
     * @param CodecInterface $codec The codec to use when encoding or decoding
     *     UUID strings
     * @param TimeConverterInterface $timeConverter The time converter to use
     *     for converting timestamps extracted from a UUID to unix timestamps
     */
    public function __construct(Rfc4122FieldsInterface $fields, NumberConverterInterface $numberConverter, CodecInterface $codec, TimeConverterInterface $timeConverter) {
        if ($fields->getVersion() !== Uuid::UUID_TYPE_DCE_SECURITY) {
            throw new InvalidArgumentException('Fields used to create a UuidV2 must represent a ' . 'version 2 (DCE Security) UUID');
        }
        parent::__construct($fields, $numberConverter, $codec, $timeConverter);
    }
    
    /**
     * Returns the local domain used to create this version 2 UUID
     */
    public function getLocalDomain() : int {
        
        /** @var Rfc4122FieldsInterface $fields */
        $fields = $this->getFields();
        return (int) hexdec($fields->getClockSeqLow()
            ->toString());
    }
    
    /**
     * Returns the string name of the local domain
     */
    public function getLocalDomainName() : string {
        return Uuid::DCE_DOMAIN_NAMES[$this->getLocalDomain()];
    }
    
    /**
     * Returns the local identifier for the domain used to create this version 2 UUID
     */
    public function getLocalIdentifier() : IntegerObject {
        
        /** @var Rfc4122FieldsInterface $fields */
        $fields = $this->getFields();
        return new IntegerObject($this->numberConverter
            ->fromHex($fields->getTimeLow()
            ->toString()));
    }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title
DeprecatedUuidMethodsTrait::getClockSeqHiAndReserved Deprecated public function
DeprecatedUuidMethodsTrait::getClockSeqHiAndReservedHex Deprecated public function
DeprecatedUuidMethodsTrait::getClockSeqLow Deprecated public function
DeprecatedUuidMethodsTrait::getClockSeqLowHex Deprecated public function
DeprecatedUuidMethodsTrait::getClockSequence Deprecated public function
DeprecatedUuidMethodsTrait::getClockSequenceHex Deprecated public function
DeprecatedUuidMethodsTrait::getFieldsHex Deprecated public function
DeprecatedUuidMethodsTrait::getLeastSignificantBits Deprecated public function
DeprecatedUuidMethodsTrait::getLeastSignificantBitsHex Deprecated public function
DeprecatedUuidMethodsTrait::getMostSignificantBits Deprecated public function
DeprecatedUuidMethodsTrait::getMostSignificantBitsHex Deprecated public function
DeprecatedUuidMethodsTrait::getNode Deprecated public function
DeprecatedUuidMethodsTrait::getNodeHex Deprecated public function
DeprecatedUuidMethodsTrait::getNumberConverter Deprecated public function
DeprecatedUuidMethodsTrait::getTimeHiAndVersion Deprecated public function
DeprecatedUuidMethodsTrait::getTimeHiAndVersionHex Deprecated public function
DeprecatedUuidMethodsTrait::getTimeLow Deprecated public function
DeprecatedUuidMethodsTrait::getTimeLowHex Deprecated public function
DeprecatedUuidMethodsTrait::getTimeMid Deprecated public function
DeprecatedUuidMethodsTrait::getTimeMidHex Deprecated public function
DeprecatedUuidMethodsTrait::getTimestamp Deprecated public function
DeprecatedUuidMethodsTrait::getTimestampHex Deprecated public function
DeprecatedUuidMethodsTrait::getVariant Deprecated public function
DeprecatedUuidMethodsTrait::getVersion Deprecated public function
TimeTrait::getDateTime public function Returns a DateTimeInterface object representing the timestamp associated
with the UUID
Uuid::$codec protected property
Uuid::$factory private static property
Uuid::$factoryReplaced private static property which disables all optimizations for the default/happy path internal
scenarios
Uuid::$fields protected property
Uuid::$numberConverter protected property
Uuid::$timeConverter protected property
Uuid::compareTo public function Returns -1, 0, or 1 if the UUID is less than, equal to, or greater than
the other UUID
Overrides UuidInterface::compareTo
Uuid::DCE_DOMAIN_GROUP public constant DCE Security group domain
Uuid::DCE_DOMAIN_NAMES public constant DCE Security domain string names
Uuid::DCE_DOMAIN_ORG public constant DCE Security organization domain
Uuid::DCE_DOMAIN_PERSON public constant DCE Security principal domain
Uuid::equals public function Returns true if the UUID is equal to the provided object Overrides UuidInterface::equals
Uuid::fromBytes public static function Creates a UUID from a byte string
Uuid::fromDateTime public static function Creates a UUID from a DateTimeInterface instance
Uuid::fromHexadecimal public static function Creates a UUID from the Hexadecimal object
Uuid::fromInteger public static function Creates a UUID from a 128-bit integer string
Uuid::fromString public static function Creates a UUID from the string standard representation
Uuid::getBytes public function @psalm-return non-empty-string Overrides UuidInterface::getBytes
Uuid::getFactory public static function Returns the factory used to create UUIDs
Uuid::getFields public function Returns the fields that comprise this UUID Overrides UuidInterface::getFields
Uuid::getHex public function Returns the hexadecimal representation of the UUID Overrides UuidInterface::getHex
Uuid::getInteger public function Returns the integer representation of the UUID Overrides UuidInterface::getInteger
Uuid::getUrn public function Returns the string standard representation of the UUID as a URN Overrides UuidInterface::getUrn
Uuid::isValid public static function Returns true if the provided string is a valid UUID
Uuid::jsonSerialize public function Converts the UUID to a string for JSON serialization
Uuid::MAX public constant The max UUID is a special form of UUID that is specified to have all 128
bits set to one
Uuid::NAMESPACE_DNS public constant When this namespace is specified, the name string is a fully-qualified
domain name
Uuid::NAMESPACE_OID public constant When this namespace is specified, the name string is an ISO OID
Uuid::NAMESPACE_URL public constant When this namespace is specified, the name string is a URL
Uuid::NAMESPACE_X500 public constant When this namespace is specified, the name string is an X.500 DN in DER
or a text output format
Uuid::NIL public constant The nil UUID is a special form of UUID that is specified to have all 128
bits set to zero
Uuid::RESERVED_FUTURE public constant Variant: reserved for future definition
Uuid::RESERVED_MICROSOFT public constant Variant: reserved, Microsoft Corporation backward compatibility
Uuid::RESERVED_NCS public constant Variant: reserved, NCS backward compatibility
Uuid::RFC_4122 public constant Variant: the UUID layout specified in RFC 4122
Uuid::serialize public function Converts the UUID to a string for PHP serialization
Uuid::setFactory public static function Sets the factory used to create UUIDs
Uuid::toString public function @psalm-return non-empty-string Overrides UuidInterface::toString
Uuid::unserialize public function Re-constructs the object from its serialized form
Uuid::uuid1 public static function Returns a version 1 (Gregorian time) UUID from a host ID, sequence number,
and the current time
Uuid::uuid2 public static function Returns a version 2 (DCE Security) UUID from a local domain, local
identifier, host ID, clock sequence, and the current time
Uuid::uuid3 public static function Returns a version 3 (name-based) UUID based on the MD5 hash of a
namespace ID and a name
Uuid::uuid4 public static function Returns a version 4 (random) UUID
Uuid::uuid5 public static function Returns a version 5 (name-based) UUID based on the SHA-1 hash of a
namespace ID and a name
Uuid::uuid6 public static function Returns a version 6 (reordered time) UUID from a host ID, sequence number,
and the current time
Uuid::uuid7 public static function Returns a version 7 (Unix Epoch time) UUID
Uuid::uuid8 public static function Returns a version 8 (custom) UUID
Uuid::UUID_TYPE_CUSTOM public constant @link https://datatracker.ietf.org/doc/html/draft-ietf-uuidrev-rfc4122bis-00#section-5.8 UUID Version 8
Uuid::UUID_TYPE_DCE_SECURITY public constant Version 2 (DCE Security) UUID
Uuid::UUID_TYPE_HASH_MD5 public constant Version 3 (name-based and hashed with MD5) UUID
Uuid::UUID_TYPE_HASH_SHA1 public constant Version 5 (name-based and hashed with SHA1) UUID
Uuid::UUID_TYPE_IDENTIFIER Deprecated public constant
Uuid::UUID_TYPE_PEABODY Deprecated public constant
Uuid::UUID_TYPE_RANDOM public constant Version 4 (random) UUID
Uuid::UUID_TYPE_REORDERED_TIME public constant Version 6 (reordered time) UUID
Uuid::UUID_TYPE_TIME public constant Version 1 (Gregorian time) UUID
Uuid::UUID_TYPE_UNIX_TIME public constant Version 7 (Unix Epoch time) UUID
Uuid::VALID_PATTERN Deprecated public constant
Uuid::__serialize public function
Uuid::__toString public function @psalm-return non-empty-string Overrides UuidInterface::__toString
Uuid::__unserialize public function
UuidV2::getLocalDomain public function Returns the local domain used to create this version 2 UUID
UuidV2::getLocalDomainName public function Returns the string name of the local domain
UuidV2::getLocalIdentifier public function Returns the local identifier for the domain used to create this version 2 UUID
UuidV2::__construct public function Creates a version 2 (DCE Security) UUID Overrides Uuid::__construct

API Navigation

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