Tsugi

Guid
in package

Printable guids for the four core LTI rows.

The database column is BINARY(16). Callers see 32 lowercase hex characters. A stored guid is never replaced. A null guid is filled by generating a candidate, writing it only while the column is still null, then reading the stored bytes back. The object keeps that read, so two requests that generate different candidates end up with the one row that won.

New values are UUID version 7 from uuid7(). That is standard byte order, the same layout as UNHEX of a hex UUID, not the MySQL UUID_TO_BIN swap.

Table of Contents

Constants

TABLES  : mixed = array('lti_user' => 'user_id', 'lti_context' =>...

Properties

$sqlCount  : mixed
Statements run by ensure() and the read used when a row omitted the column.

Methods

ensure()  : string|null
32-character lowercase hex for this primary key.
forRow()  : string|null
Hex guid for a row being turned into an object.
uuid7()  : string
UUID version 7 as 32 lowercase hex characters.
allowed()  : mixed
hexFromValue()  : string|null
BINARY(16) or an already-printable 32-hex string. Anything else is null.
physical()  : mixed
Physical table name, or null when the prefix is not a plain identifier.
readGuid()  : array{found: bool, binary: mixed}
rowId()  : mixed

Constants

TABLES

private mixed TABLES = array('lti_user' => 'user_id', 'lti_context' => 'context_id', 'lti_key' => 'key_id', 'lti_link' => 'link_id')

Properties

$sqlCount

Statements run by ensure() and the read used when a row omitted the column.

private static mixed $sqlCount = 0

Methods

ensure()

32-character lowercase hex for this primary key.

public static ensure(string $table, string $pkColumn, int $id, string|null $binary) : string|null

A usable guid already in $binary is returned with no SQL. Null means the column is null: generate a candidate, store it only while the column is still null, then SELECT the row and return bin2hex of those stored bytes. The candidate is never returned. Zero updated rows is not a failure; another request may have written first. A missing row or a still-null column returns null.

Uses the connection's current transaction. Does not commit.

Parameters
$table : string

lti_user, lti_context, lti_key, or lti_link

$pkColumn : string
$id : int
$binary : string|null

BINARY(16), or null

Return values
string|null

forRow()

Hex guid for a row being turned into an object.

public static forRow(array<string, mixed> $row, mixed $table, mixed $pkColumn, array<int, string> $idKeys, array<int, string> $guidKeys) : string|null

No primary key: return null and do not touch the database. That covers a new object and a LEFT JOIN that did not match.

The guid column is present and non-null: convert it and run no SQL. The guid column is present and null: fill it if it is still null. The guid column was not selected: read the row first. Fill only when that read shows a real row whose guid is null.

Parameters
$row : array<string, mixed>
$table : mixed
$pkColumn : mixed
$idKeys : array<int, string>
$guidKeys : array<int, string>
Return values
string|null

uuid7()

UUID version 7 as 32 lowercase hex characters.

public static uuid7() : string

48-bit Unix time in milliseconds, version nibble 7, the RFC 4122 variant, and random bits in the rest. Standard byte order.

Return values
string

allowed()

private static allowed(mixed $table, mixed $pkColumn) : mixed
Parameters
$table : mixed
$pkColumn : mixed

hexFromValue()

BINARY(16) or an already-printable 32-hex string. Anything else is null.

private static hexFromValue(mixed $binary) : string|null
Parameters
$binary : mixed
Return values
string|null

physical()

Physical table name, or null when the prefix is not a plain identifier.

private static physical(mixed $table) : mixed
Parameters
$table : mixed

readGuid()

private static readGuid(mixed $table, mixed $pkColumn, mixed $id) : array{found: bool, binary: mixed}
Parameters
$table : mixed
$pkColumn : mixed
$id : mixed
Return values
array{found: bool, binary: mixed}

rowId()

private static rowId(array<string, mixed> $row, array<int, string> $idKeys) : mixed
Parameters
$row : array<string, mixed>
$idKeys : array<int, string>

        
On this page

Search results