Methods |
public
|
__construct(
FieldsInterface $fields,
NumberConverterInterface $numberConverter,
CodecInterface $codec,
TimeConverterInterface $timeConverter,
)
Creates a universally unique identifier (UUID) from an array of fields
Creates a universally unique identifier (UUID) from an array of fields
Unless you're making advanced use of this library to generate identifiers that deviate from RFC 9562 (formerly
RFC 4122), you probably do not want to instantiate a UUID directly. Use the static methods, instead:
use Ramsey\Uuid\Uuid;
$timeBasedUuid = Uuid::uuid1();
$namespaceMd5Uuid = Uuid::uuid3(Uuid::NAMESPACE_URL, 'http://php.net/');
$randomUuid = Uuid::uuid4();
$namespaceSha1Uuid = Uuid::uuid5(Uuid::NAMESPACE_URL, 'http://php.net/');
Parameters
$fields |
The fields from which to construct a UUID
|
$numberConverter |
The number converter to use for converting hex values to/from integers
|
$codec |
The codec to use when encoding or decoding UUID strings
|
$timeConverter |
The time converter to use for converting timestamps extracted from a
UUID to unix timestamps
|
|
#
|
public
|
__toString(): non-empty-string
|
#
|
public
|
jsonSerialize(): string
Converts the UUID to a string for JSON serialization
Converts the UUID to a string for JSON serialization
Implements
|
#
|
public
|
serialize(): string
Converts the UUID to a string for PHP serialization
Converts the UUID to a string for PHP serialization
Implements
|
#
|
public
|
__serialize(): array{bytes: string}
|
#
|
public
|
unserialize(string $data): void
Re-constructs the object from its serialized form
Re-constructs the object from its serialized form
Parameters
$data |
The serialized PHP string to unserialize into a UuidInterface instance
|
Implements
|
#
|
public
|
__unserialize(array{bytes?: string} $data): void
|
#
|
public
|
compareTo(UuidInterface $other): int
Returns -1, 0, or 1 if the UUID is less than, equal to, or greater than the other UUID
Returns -1, 0, or 1 if the UUID is less than, equal to, or greater than the other UUID
The first of two UUIDs is greater than the second if the most significant field in which the UUIDs differ is
greater for the first UUID.
Parameters
$other |
The UUID to compare
|
Returns
-1, 0, or 1 if the UUID is less than, equal to, or greater than $other
Implements
|
#
|
public
|
equals(?object $other): bool
Returns true if the UUID is equal to the provided object
Returns true if the UUID is equal to the provided object
The result is true if and only if the argument is not null, is a UUID object, has the same variant, and contains
the same value, bit-for-bit, as the UUID.
Parameters
$other |
An object to test for equality with this UUID
|
Returns
True if the other object is equal to this UUID
Implements
|
#
|
public
|
getBytes(): non-empty-string
Returns the binary string representation of the UUID
Returns the binary string representation of the UUID
Implements
|
#
|
public
|
getFields(): FieldsInterface
Returns the fields that comprise this UUID
Returns the fields that comprise this UUID
Implements
|
#
|
public
|
getHex(): Hexadecimal
Returns the hexadecimal representation of the UUID
Returns the hexadecimal representation of the UUID
Implements
|
#
|
public
|
getInteger(): Integer
Returns the integer representation of the UUID
Returns the integer representation of the UUID
Implements
|
#
|
public
|
getUrn(): string
Returns the string standard representation of the UUID as a URN
Returns the string standard representation of the UUID as a URN
Implements
|
#
|
public
|
toString(): non-empty-string
Returns the string standard representation of the UUID
Returns the string standard representation of the UUID
Implements
|
#
|
public
static
|
getFactory(): UuidFactoryInterface
Returns the factory used to create UUIDs
Returns the factory used to create UUIDs
|
#
|
public
static
|
setFactory(UuidFactoryInterface $factory): void
Sets the factory used to create UUIDs
Sets the factory used to create UUIDs
Parameters
$factory |
A factory that will be used by this class to create UUIDs
|
|
#
|
public
static
|
fromBytes(string $bytes): UuidInterface
Creates a UUID from a byte string
Creates a UUID from a byte string
Parameters
Returns
A UuidInterface instance created from a binary string representation
Throws
|
#
|
public
static
|
fromString(string $uuid): UuidInterface
Creates a UUID from the string standard representation
Creates a UUID from the string standard representation
Parameters
$uuid |
A hexadecimal string
|
Returns
A UuidInterface instance created from a hexadecimal string representation
Throws
|
#
|
public
static
|
fromDateTime(DateTimeInterface $dateTime, Hexadecimal|null $node = null, int|null $clockSeq = null): UuidInterface
Creates a UUID from a DateTimeInterface instance
Creates a UUID from a DateTimeInterface instance
Parameters
$dateTime |
The date and time
|
$node |
A 48-bit number representing the hardware address
|
$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
|
Returns
A UuidInterface instance that represents a version 1 UUID created from a DateTimeInterface instance
|
#
|
public
static
|
fromHexadecimal(Hexadecimal $hex): UuidInterface
Creates a UUID from the Hexadecimal object
Creates a UUID from the Hexadecimal object
Parameters
$hex |
Hexadecimal object representing a hexadecimal number
|
Returns
A UuidInterface instance created from the Hexadecimal object representing a hexadecimal number
Throws
|
#
|
public
static
|
fromInteger(string $integer): UuidInterface
Creates a UUID from a 128-bit integer string
Creates a UUID from a 128-bit integer string
Parameters
$integer |
String representation of 128-bit integer
|
Returns
A UuidInterface instance created from the string representation of a 128-bit integer
Throws
|
#
|
public
static
|
isValid(string $uuid): bool
Returns true if the provided string is a valid UUID
Returns true if the provided string is a valid UUID
Parameters
$uuid |
A string to validate as a UUID
|
Returns
True if the string is a valid UUID, false otherwise
|
#
|
public
static
|
uuid1(Hexadecimal|int|string|null $node = null, int|null $clockSeq = null): UuidInterface
Returns a version 1 (Gregorian time) UUID from a host ID, sequence number, and the current time
Returns a version 1 (Gregorian time) UUID from a host ID, sequence number, and the current time
Parameters
$node |
A 48-bit number representing the hardware address; this number may
be represented as an integer or a hexadecimal string
|
$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
|
Returns
A UuidInterface instance that represents a version 1 UUID
|
#
|
public
static
|
uuid2(
int $localDomain,
Integer|null $localIdentifier = null,
Hexadecimal|null $node = null,
int|null $clockSeq = null,
): UuidInterface
Returns a version 2 (DCE Security) UUID from a local domain, local identifier, host ID, clock sequence, and the current…
Returns a version 2 (DCE Security) UUID from a local domain, local identifier, host ID, clock sequence, and the current time
Parameters
$localDomain |
The local domain to use when generating bytes, according to DCE Security
|
$localIdentifier |
The local identifier for the given domain; this may be a UID or GID
on POSIX systems, if the local domain is "person" or "group," or it may be a site-defined identifier if the
local domain is "org"
|
$node |
A 48-bit number representing the hardware address
|
$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 (in a version 2 UUID, the lower 8 bits of this number are
replaced with the domain).
|
Returns
A UuidInterface instance that represents a version 2 UUID
|
#
|
public
static
|
uuid3(UuidInterface|string $ns, string $name): UuidInterface
Returns a version 3 (name-based) UUID based on the MD5 hash of a namespace ID and a name
Returns a version 3 (name-based) UUID based on the MD5 hash of a namespace ID and a name
Parameters
$ns |
The namespace (must be a valid UUID)
|
$name |
The name to use for creating a UUID
|
Returns
A UuidInterface instance that represents a version 3 UUID
|
#
|
public
static
|
uuid4(): UuidInterface
Returns a version 4 (random) UUID
Returns a version 4 (random) UUID
Returns
A UuidInterface instance that represents a version 4 UUID
|
#
|
public
static
|
uuid5(UuidInterface|string $ns, string $name): UuidInterface
Returns a version 5 (name-based) UUID based on the SHA-1 hash of a namespace ID and a name
Returns a version 5 (name-based) UUID based on the SHA-1 hash of a namespace ID and a name
Parameters
$ns |
The namespace (must be a valid UUID)
|
$name |
The name to use for creating a UUID
|
Returns
A UuidInterface instance that represents a version 5 UUID
|
#
|
public
static
|
uuid6(Hexadecimal|null $node = null, int|null $clockSeq = null): UuidInterface
Returns a version 6 (reordered Gregorian time) UUID from a host ID, sequence number, and the current time
Returns a version 6 (reordered Gregorian time) UUID from a host ID, sequence number, and the current time
Parameters
$node |
A 48-bit number representing the hardware address
|
$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
|
Returns
A UuidInterface instance that represents a version 6 UUID
|
#
|
public
static
|
uuid7(DateTimeInterface|null $dateTime = null): UuidInterface
Returns a version 7 (Unix Epoch time) UUID
Returns a version 7 (Unix Epoch time) UUID
Parameters
$dateTime |
An optional date/time from which to create the version 7 UUID. If not
provided, the UUID is generated using the current date/time.
|
Returns
A UuidInterface instance that represents a version 7 UUID
|
#
|
public
static
|
uuid8(string $bytes): UuidInterface
Returns a version 8 (custom format) UUID
Returns a version 8 (custom format) UUID
The bytes provided may contain any value according to your application's needs. Be aware, however, that other
applications may not understand the semantics of the value.
Parameters
$bytes |
A 16-byte octet string. This is an open blob of data that you may fill with 128 bits of
information. Be aware, however, bits 48 through 51 will be replaced with the UUID version field, and bits 64
and 65 will be replaced with the UUID variant. You MUST NOT rely on these bits for your application needs.
|
Returns
A UuidInterface instance that represents a version 8 UUID
|
#
|
Constants |
public
|
NAMESPACE_DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8'
When this namespace is specified, the name string is a fully qualified domain name
When this namespace is specified, the name string is a fully qualified domain name
|
#
|
public
|
NAMESPACE_URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8'
When this namespace is specified, the name string is a URL
When this namespace is specified, the name string is a URL
|
#
|
public
|
NAMESPACE_OID = '6ba7b812-9dad-11d1-80b4-00c04fd430c8'
When this namespace is specified, the name string is an ISO OID
When this namespace is specified, the name string is an ISO OID
|
#
|
public
|
NAMESPACE_X500 = '6ba7b814-9dad-11d1-80b4-00c04fd430c8'
When this namespace is specified, the name string is an X.500 DN (in DER or a text output format)
When this namespace is specified, the name string is an X.500 DN (in DER or a text output format)
|
#
|
public
|
NIL = '00000000-0000-0000-0000-000000000000'
The Nil UUID is a special form of UUID that is specified to have all 128 bits set to zero
The Nil UUID is a special form of UUID that is specified to have all 128 bits set to zero
|
#
|
public
|
MAX = 'ffffffff-ffff-ffff-ffff-ffffffffffff'
The Max UUID is a special form of UUID that is specified to have all 128 bits set to one
The Max UUID is a special form of UUID that is specified to have all 128 bits set to one
|
#
|
public
|
RESERVED_NCS = 0
Variant: reserved, NCS backward compatibility
Variant: reserved, NCS backward compatibility
|
#
|
public
|
RFC_4122 = 2
Variant: the UUID layout specified in RFC 9562 (formerly RFC 4122)
Variant: the UUID layout specified in RFC 9562 (formerly RFC 4122)
|
#
|
public
|
RFC_9562 = 2
Variant: the UUID layout specified in RFC 9562 (formerly RFC 4122)
Variant: the UUID layout specified in RFC 9562 (formerly RFC 4122)
|
#
|
public
|
RESERVED_MICROSOFT = 6
Variant: reserved, Microsoft Corporation backward compatibility
Variant: reserved, Microsoft Corporation backward compatibility
|
#
|
public
|
RESERVED_FUTURE = 7
Variant: reserved for future definition
Variant: reserved for future definition
|
#
|
public
|
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}$'
|
#
|
public
|
UUID_TYPE_TIME = 1
Version 1 (Gregorian time) UUID
Version 1 (Gregorian time) UUID
|
#
|
public
|
UUID_TYPE_DCE_SECURITY = 2
Version 2 (DCE Security) UUID
Version 2 (DCE Security) UUID
|
#
|
public
|
UUID_TYPE_IDENTIFIER = 2
|
#
|
public
|
UUID_TYPE_HASH_MD5 = 3
Version 3 (name-based and hashed with MD5) UUID
Version 3 (name-based and hashed with MD5) UUID
|
#
|
public
|
UUID_TYPE_RANDOM = 4
Version 4 (random) UUID
|
#
|
public
|
UUID_TYPE_HASH_SHA1 = 5
Version 5 (name-based and hashed with SHA1) UUID
Version 5 (name-based and hashed with SHA1) UUID
|
#
|
public
|
UUID_TYPE_PEABODY = 6
|
#
|
public
|
UUID_TYPE_REORDERED_TIME = 6
Version 6 (reordered Gregorian time) UUID
Version 6 (reordered Gregorian time) UUID
|
#
|
public
|
UUID_TYPE_UNIX_TIME = 7
Version 7 (Unix Epoch time) UUID
Version 7 (Unix Epoch time) UUID
|
#
|
public
|
UUID_TYPE_CUSTOM = 8
Version 8 (custom format) UUID
Version 8 (custom format) UUID
|
#
|
public
|
DCE_DOMAIN_PERSON = 0
DCE Security principal domain
DCE Security principal domain
|
#
|
public
|
DCE_DOMAIN_GROUP = 1
DCE Security group domain
DCE Security group domain
|
#
|
public
|
DCE_DOMAIN_ORG = 2
DCE Security organization domain
DCE Security organization domain
|
#
|
public
|
DCE_DOMAIN_NAMES = [
self::DCE_DOMAIN_PERSON => 'person',
self::DCE_DOMAIN_GROUP => 'group',
self::DCE_DOMAIN_ORG => 'org',
]
DCE Security domain string names
DCE Security domain string names
|
#
|