Getting Started

Custom Extension

Custom extension for Xefi Faker PHP

You can easily create a customized Faker extension. To do so, simply define a PHP class that extends the Xefi\Faker\Extensions\Extension class, and define the functions you wish to make available.

Example

use Xefi\Faker\Extensions\Extension;

class CustomEmailExtension extends Extension
{
    public function generateRandomEmail(string $domainName): mixed
    {
        $randomBytes = $this->randomizer->getBytes(4);
        $localPart = strtolower(bin2hex($randomBytes));
        return $localPart . '@' . $domainName;
    }
}

$this->randomizer is the PHP 8 Randomizer instance

You'll also need to load your extension into Faker

faker()->resolveExtensions([CustomEmailExtension::class])

Copyright © 2026