Documentation

TimestampFirstCombCodec extends StringCodec
in package

TimestampFirstCombCodec encodes and decodes COMBs, with the timestamp as the first 48 bits

In contrast with the TimestampLastCombCodec, the TimestampFirstCombCodec adds the timestamp to the first 48 bits of the COMB. To generate a timestamp-first COMB, set the TimestampFirstCombCodec as the codec, along with the CombGenerator as the random generator.

$factory = new UuidFactory();

$factory->setCodec(new TimestampFirstCombCodec($factory->getUuidBuilder()));

$factory->setRandomGenerator(new CombGenerator(
    $factory->getRandomGenerator(),
    $factory->getNumberConverter()
));

$timestampFirstComb = $factory->uuid4();
Tags
link

The Cost of GUIDs as Primary Keys

psalm-immutable

Table of Contents

$builder  : UuidBuilderInterface
__construct()  : mixed
Constructs a StringCodec
decode()  : UuidInterface
Returns a UuidInterface derived from a hexadecimal string representation
decodeBytes()  : UuidInterface
Returns a UuidInterface derived from a binary string representation
encode()  : string
Returns a hexadecimal string representation of a UuidInterface
encodeBinary()  : string
Returns a binary string representation of a UuidInterface
getBuilder()  : UuidBuilderInterface
Returns the UUID builder
getBytes()  : string
Returns a byte string of the UUID
swapBytes()  : string
Swaps bytes according to the timestamp-first COMB rules

Properties

Methods

decode()

Returns a UuidInterface derived from a hexadecimal string representation

public decode(string $encodedUuid) : UuidInterface
Parameters
$encodedUuid : string

The hexadecimal string representation to convert into a UuidInterface instance

Tags
throws
InvalidUuidStringException
inheritDoc
Return values
UuidInterface

An instance of a UUID decoded from a hexadecimal string representation

decodeBytes()

Returns a UuidInterface derived from a binary string representation

public decodeBytes(string $bytes) : UuidInterface
Parameters
$bytes : string

The binary string representation to convert into a UuidInterface instance

Return values
UuidInterface

An instance of a UUID decoded from a binary string representation

encode()

Returns a hexadecimal string representation of a UuidInterface

public encode(UuidInterface $uuid) : string
Parameters
$uuid : UuidInterface

The UUID for which to create a hexadecimal string representation

Tags
psalm-return

non-empty-string

psalm-suppress

MoreSpecificReturnType we know that the retrieved string is never empty

psalm-suppress

LessSpecificReturnStatement we know that the retrieved string is never empty

Return values
string

Hexadecimal string representation of a UUID

encodeBinary()

Returns a binary string representation of a UuidInterface

public encodeBinary(UuidInterface $uuid) : string
Parameters
$uuid : UuidInterface

The UUID for which to create a binary string representation

Tags
psalm-return

non-empty-string

psalm-suppress

MoreSpecificReturnType we know that the retrieved string is never empty

psalm-suppress

LessSpecificReturnStatement we know that the retrieved string is never empty

Return values
string

Binary string representation of a UUID

getBytes()

Returns a byte string of the UUID

protected getBytes(string $encodedUuid) : string
Parameters
$encodedUuid : string
Return values
string

swapBytes()

Swaps bytes according to the timestamp-first COMB rules

private swapBytes(string $bytes) : string
Parameters
$bytes : string
Return values
string

Search results