class UuidFactory implements UuidFactoryInterface (View source)

Methods

__construct(FeatureSet $features = null)

Constructs a UuidFactory for creating Ramsey\Uuid\UuidInterface instances

getCodec()

Returns the UUID coder-decoder used by this factory

setCodec(CodecInterface $codec)

Sets the UUID coder-decoder used by this factory

getNodeProvider()

Returns the system node ID provider used by this factory

getRandomGenerator()

Returns the random UUID generator used by this factory

getTimeGenerator()

Returns the time-based UUID generator used by this factory

setTimeGenerator(TimeGeneratorInterface $generator)

Sets the time-based UUID generator this factory will use to generate version 1 UUIDs

getNumberConverter()

Returns the number converter used by this factory

setRandomGenerator(RandomGeneratorInterface $generator)

Sets the random UUID generator this factory will use to generate version 4 UUIDs

setNumberConverter(NumberConverterInterface $converter)

Sets the number converter this factory will use

getUuidBuilder()

Returns the UUID builder this factory uses when creating Uuid instances

setUuidBuilder(UuidBuilderInterface $builder)

Sets the UUID builder this factory will use when creating Uuid instances

fromBytes(string $bytes)

Creates a UUID from a byte string.

fromString(string $uuid)

Creates a UUID from the string standard representation

fromInteger(mixed $integer)

Creates a Uuid from an integer representation

uuid1(int|string $node = null, int $clockSeq = null)

Generate a version 1 UUID from a host ID, sequence number, and the current time.

uuid3(string $ns, string $name)

Generate a version 3 UUID based on the MD5 hash of a namespace identifier (which is a UUID) and a name (which is a string).

uuid4()

Generate a version 4 (random) UUID.

uuid5(string $ns, string $name)

Generate a version 5 UUID based on the SHA-1 hash of a namespace identifier (which is a UUID) and a name (which is a string).

uuid(array $fields)

Returns a Uuid

uuidFromNsAndName(string|UuidInterface $ns, string $name, int $version, string $hashFunction)

Returns a version 3 or 5 namespaced Uuid

uuidFromHashedName(string $hash, int $version)

Returns a Uuid created from $hash with the version field set to $version and the variant field set for RFC 4122

Details

__construct(FeatureSet $features = null)

Constructs a UuidFactory for creating Ramsey\Uuid\UuidInterface instances

Parameters

FeatureSet $features A set of features for use when creating UUIDs

CodecInterface getCodec()

Returns the UUID coder-decoder used by this factory

Return Value

CodecInterface

setCodec(CodecInterface $codec)

Sets the UUID coder-decoder used by this factory

Parameters

CodecInterface $codec

NodeProviderInterface getNodeProvider()

Returns the system node ID provider used by this factory

Return Value

NodeProviderInterface

RandomGeneratorInterface getRandomGenerator()

Returns the random UUID generator used by this factory

TimeGeneratorInterface getTimeGenerator()

Returns the time-based UUID generator used by this factory

Return Value

TimeGeneratorInterface

setTimeGenerator(TimeGeneratorInterface $generator)

Sets the time-based UUID generator this factory will use to generate version 1 UUIDs

Parameters

TimeGeneratorInterface $generator

NumberConverterInterface getNumberConverter()

Returns the number converter used by this factory

setRandomGenerator(RandomGeneratorInterface $generator)

Sets the random UUID generator this factory will use to generate version 4 UUIDs

Parameters

RandomGeneratorInterface $generator

setNumberConverter(NumberConverterInterface $converter)

Sets the number converter this factory will use

Parameters

NumberConverterInterface $converter

UuidBuilderInterface getUuidBuilder()

Returns the UUID builder this factory uses when creating Uuid instances

Return Value

UuidBuilderInterface $builder

setUuidBuilder(UuidBuilderInterface $builder)

Sets the UUID builder this factory will use when creating Uuid instances

Parameters

UuidBuilderInterface $builder

UuidInterface fromBytes(string $bytes)

Creates a UUID from a byte string.

Parameters

string $bytes A 16-byte string representation of a UUID

Return Value

UuidInterface

UuidInterface fromString(string $uuid)

Creates a UUID from the string standard representation

Parameters

string $uuid A string representation of a UUID

Return Value

UuidInterface

UuidInterface fromInteger(mixed $integer)

Creates a Uuid from an integer representation

The integer representation may be a real integer, a string integer, or an integer representation supported by a configured number converter.

Parameters

mixed $integer The integer to use when creating a Uuid from an integer; may be of any type understood by the configured number converter

Return Value

UuidInterface

UuidInterface uuid1(int|string $node = null, int $clockSeq = null)

Generate a version 1 UUID from a host ID, sequence number, and the current time.

Parameters

int|string $node A 48-bit number representing the hardware address This number may be represented as an integer or a hexadecimal string.
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 Value

UuidInterface

UuidInterface uuid3(string $ns, string $name)

Generate a version 3 UUID based on the MD5 hash of a namespace identifier (which is a UUID) and a name (which is a string).

Parameters

string $ns The UUID namespace in which to create the named UUID
string $name The name to create a UUID for

Return Value

UuidInterface

UuidInterface uuid4()

Generate a version 4 (random) UUID.

Return Value

UuidInterface

UuidInterface uuid5(string $ns, string $name)

Generate a version 5 UUID based on the SHA-1 hash of a namespace identifier (which is a UUID) and a name (which is a string).

Parameters

string $ns The UUID namespace in which to create the named UUID
string $name The name to create a UUID for

Return Value

UuidInterface

UuidInterface uuid(array $fields)

Returns a Uuid

Uses the configured builder and codec and the provided array of hexadecimal value UUID fields to construct a Uuid object.

Parameters

array $fields An array of fields from which to construct a UUID; see {see \Ramsey\Uuid\UuidInterface::getFieldsHex()} for array structure.

Return Value

UuidInterface

protected UuidInterface uuidFromNsAndName(string|UuidInterface $ns, string $name, int $version, string $hashFunction)

Returns a version 3 or 5 namespaced Uuid

Parameters

string|UuidInterface $ns The UUID namespace to use
string $name The string to hash together with the namespace
int $version The version of UUID to create (3 or 5)
string $hashFunction The hash function to use when hashing together the namespace and name

Return Value

UuidInterface

protected UuidInterface uuidFromHashedName(string $hash, int $version)

Returns a Uuid created from $hash with the version field set to $version and the variant field set for RFC 4122

Parameters

string $hash The hash to use when creating the UUID
int $version The UUID version to set for this hash (1, 3, 4, or 5)

Return Value

UuidInterface