CombGenerator
in package
implements
RandomGeneratorInterface
CombGenerator generates COMBs (combined UUID/timestamp)
The CombGenerator, when used with the StringCodec (and, by proxy, the TimestampLastCombCodec) or the TimestampFirstCombCodec, combines the current timestamp with a UUID (hence the name "COMB"). The timestamp either appears as the first or last 48 bits of the COMB, depending on the codec used.
By default, COMBs will have the timestamp set as the last 48 bits of the identifier.
$factory = new UuidFactory();
$factory->setRandomGenerator(new CombGenerator(
$factory->getRandomGenerator(),
$factory->getNumberConverter()
));
$comb = $factory->uuid4();
To generate a COMB with the timestamp as the first 48 bits, set the TimestampFirstCombCodec as the codec.
$factory->setCodec(new TimestampFirstCombCodec($factory->getUuidBuilder()));
Tags
Interfaces, Classes, Traits and Enums
- RandomGeneratorInterface
- A random generator generates strings of random binary data
Table of Contents
- TIMESTAMP_BYTES = 6
- $converter : NumberConverterInterface
- $randomGenerator : RandomGeneratorInterface
- __construct() : mixed
- generate() : string
- Generates a string of randomized binary data
- timestamp() : string
- Returns current timestamp a string integer, precise to 0.00001 seconds
Constants
TIMESTAMP_BYTES
public
mixed
TIMESTAMP_BYTES
= 6
Properties
$converter
private
NumberConverterInterface
$converter
$randomGenerator
private
RandomGeneratorInterface
$randomGenerator
Methods
__construct()
public
__construct(RandomGeneratorInterface $generator, NumberConverterInterface $numberConverter) : mixed
Parameters
- $generator : RandomGeneratorInterface
- $numberConverter : NumberConverterInterface
Return values
mixed —generate()
Generates a string of randomized binary data
public
generate(int $length) : string
Parameters
- $length : int
-
The number of bytes of random binary data to generate
Tags
Return values
string —A binary string
timestamp()
Returns current timestamp a string integer, precise to 0.00001 seconds
private
timestamp() : string