Uuids
in package
implements
Iterator
UUIDs class for handling UUID operations
This class provides functionality for generating and managing UUIDs using various methods and formats.
Table of Contents
Interfaces
- Iterator
Constants
- MODE_HYBRID : mixed = 'hybrid'
- MODE_RANDOM : mixed = 'random'
- MODE_ULID : mixed = 'ulid'
- MODE_UUID7 : mixed = 'uuid7'
- ALPHABET : mixed = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJ...
Properties
Methods
- __construct() : mixed
- Constructor for Uuids class
- current() : string
- key() : int
- next() : void
- Generate the next UUID in the sequence.
- nextBytes() : string
- Generates the specified number of random bytes.
- nextId() : string
- Generates and returns the next ID, advancing the internal pointer.
- nextInt() : int
- Generates the next pseudo-random integer between $min and $max.
- nextString() : string
- Generates the next random string of specified length using the configured alphabet.
- rewind() : void
- Rewind the iterator to the first element.
- valid() : bool
- generate() : string
Constants
MODE_HYBRID
public
mixed
MODE_HYBRID
= 'hybrid'
MODE_RANDOM
public
mixed
MODE_RANDOM
= 'random'
MODE_ULID
public
mixed
MODE_ULID
= 'ulid'
MODE_UUID7
public
mixed
MODE_UUID7
= 'uuid7'
ALPHABET
private
mixed
ALPHABET
= '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
Properties
$current
private
string
$current
$extra
private
int
$extra
$length
private
int
$length
$mode
private
string
$mode
$position
private
int
$position
= 0
$rng
private
Randomizer
$rng
Methods
__construct()
Constructor for Uuids class
public
__construct([string $mode = self::MODE_ULID ][, int $length = 32 ][, int $extra = 16 ][, Randomizer|null $rng = null ]) : mixed
Parameters
- $mode : string = self::MODE_ULID
- $length : int = 32
- $extra : int = 16
- $rng : Randomizer|null = null
current()
public
current() : string
Return values
stringkey()
public
key() : int
Return values
intnext()
Generate the next UUID in the sequence.
public
next() : void
This method advances the internal pointer and generates a new UUID based on the configured mode (ulid, uuid7, random, or hybrid).
nextBytes()
Generates the specified number of random bytes.
public
nextBytes([int $length = 32 ]) : string
This method uses the internal randomizer to generate a string of bytes, which can be used for cryptographic purposes or other needs requiring cryptographically secure randomness.
Parameters
- $length : int = 32
-
The number of bytes to generate. Defaults to 32.
Return values
string —Returns a string containing the specified number of random bytes.
nextId()
Generates and returns the next ID, advancing the internal pointer.
public
nextId() : string
This method is a helper that combines moving the iterator forward with
retrieving the new value. It's useful when you want to get the next
generated identifier without manually calling next() and current().
Return values
string —The next generated ID based on the configured mode.
nextInt()
Generates the next pseudo-random integer between $min and $max.
public
nextInt([int $min = 0 ][, int $max = PHP_INT_MAX ]) : int
Parameters
- $min : int = 0
-
The minimum value to be returned, inclusive.
- $max : int = PHP_INT_MAX
-
The maximum value to be returned, inclusive.
Return values
int —A random integer value within the specified range.
nextString()
Generates the next random string of specified length using the configured alphabet.
public
nextString([int $length = 32 ]) : string
Parameters
- $length : int = 32
-
The length of the random string to generate (default: 32)
Return values
string —The generated random string
rewind()
Rewind the iterator to the first element.
public
rewind() : void
This method resets the internal position to 0 and generates a new value.
valid()
public
valid() : bool
Return values
bool —True if the current position is valid, false otherwise. In this implementation, it always returns true since there's no limit on how many times we can call next().
generate()
private
generate() : string