-
Notifications
You must be signed in to change notification settings - Fork 10
Method Reference
The Generator
class can be instantiated with no parameters where it will use all the default config or you can optionally pass an array of config values to specfically override.
$generator = new Generator();
$generator = new Generator([
'separator' => '_',
]);
Signature: generate(?string $text = null): string
Description:
Generates a username based on input using the config loaded into the instance.
Usage:
// Generate based on input
$generator->generate('test user');
// Generate random username from dictionary
$generator->generate();
Signature: generateFor(object $model): string
Description:
Generates a username based on input from the model given using the config loaded into the instance, it will try to guess the best driver to use based on fields present on the model.
Usage:
$generator->generateFor(User::first());
Signature: setDriver(string $driverKey): self
Description:
Set the driver to use, can pass either the fully-qualified class name or key from config.
Usage:
$generator->setDriver('email');
Signature: getDriver(): BaseDriver
Description:
Gets the instance of the driver the Generator
is using.
Usage:
$generator->getDriver();
Signature: setConfig(mixed $key, mixed $value = null): self
Description:
Set config items. Can provide via associative array, or a key/value pair.
Usage:
// Array
$class->setConfig([
'separator' => '_',
]);
// Key/Value Pair
$class->setConfig('separator', '_');