class DefaultTimeGenerator implements TimeGeneratorInterface (View source)

DefaultTimeGenerator provides functionality to generate strings of binary data for version 1 UUIDs based on a host ID, sequence number, and the current time

Methods

__construct(NodeProviderInterface $nodeProvider, TimeConverterInterface $timeConverter, TimeProviderInterface $timeProvider)

Constructs a DefaultTimeGenerator using a node provider, time converter, and time provider

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

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

string
getValidNode(string|int $node)

Uses the node provider given when constructing this instance to get the node ID (usually a MAC address)

Details

__construct(NodeProviderInterface $nodeProvider, TimeConverterInterface $timeConverter, TimeProviderInterface $timeProvider)

Constructs a DefaultTimeGenerator using a node provider, time converter, and time provider

Parameters

NodeProviderInterface $nodeProvider
TimeConverterInterface $timeConverter
TimeProviderInterface $timeProvider

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

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.

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

string A binary string

protected string getValidNode(string|int $node)

Uses the node provider given when constructing this instance to get the node ID (usually a MAC address)

Parameters

string|int $node A node value that may be used to override the node provider

Return Value

string Hexadecimal representation of the node ID