UsernameGenerator

UsernameGenerator

Helper class to generate a username based on a supplied format. Guarantees the uniqueness of the returned username.

Methods

__construct

Class constructor with database dependancy injection.

UsernameGenerator::__construct( \Gibbon\Contracts\Database\Connection $pdo )

addToken

Adds a string token that’s replaced with the corresponding value when processing the username format.

UsernameGenerator::addToken( string $name, string $value )

addNumericToken

Adds a numeric token with a starting value and size that’s incremented each time it’s generated.

UsernameGenerator::addNumericToken( string $name, string|integer $value, integer $size, integer $increment, \Gibbon\Data\function $callback = null )

getToken

Get token data by name.

UsernameGenerator::getToken( string $name ): array

Return Value: array Token data


generateByRole

Generates a username based on the provided gibbonRoleID, using the ‘isDefault’ format if none exists for that role.

UsernameGenerator::generateByRole( string|integer $gibbonRoleID ): string

Return Value: string Unique username


generate

Generates a username based on the provided string format, replacing tokens with their corresponding values.

UsernameGenerator::generate( string $format ): string

Return Value: string Unique username


isUsernameUnique

Checks a username against the database for uniqueness.

UsernameGenerator::isUsernameUnique( string $username ): boolean

Return Value: boolean True if unique


Last updated : September 15, 2018 b92362d