Skip to content

Commit 0574f0d

Browse files
authored
Merge pull request #17 from 15g-lucas/custom-extension
Explanation of how to create/use a customized extension
2 parents 541f51e + ff4e29a commit 0574f0d

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: Custom Extension
3+
description: Custom extension for Xefi Faker PHP
4+
---
5+
6+
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.
7+
8+
## Example
9+
```php
10+
use Xefi\Faker\Extensions\Extension;
11+
12+
class CustomEmailExtension extends Extension
13+
{
14+
public function generateRandomEmail(string $domainName): mixed
15+
{
16+
$localPart = strtolower(bin2hex(random_bytes(4)));
17+
return $localPart . '@' . $domainName;
18+
}
19+
}
20+
```
21+
22+
You'll also need to load your extension into Faker
23+
```php
24+
faker()->resolveExtensions([CustomEmailExtension::class])
25+
```
26+
27+

0 commit comments

Comments
 (0)