Skip to content
This repository was archived by the owner on Dec 11, 2020. It is now read-only.

Commit eef0594

Browse files
authored
Merge pull request #1493 from browner12/patch-1
create `passthrough` function
2 parents c0f369a + e8a9572 commit eef0594

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

readme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,12 @@ try {
371371
}
372372
```
373373

374+
If you would like to use a modifier with a value not generated by Faker, use the `passthrough()` method. `passthrough()` simply returns whatever value it was given.
375+
376+
```php
377+
$faker->optional()->passthrough(mt_rand(5, 15));
378+
```
379+
374380
## Localization
375381

376382
`Faker\Factory` can take a locale as an argument, to return localized data. If no localized provider is found, the factory fallbacks to the default locale (en_US).

src/Faker/Provider/Base.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,18 @@ public static function numberBetween($int1 = 0, $int2 = 2147483647)
139139
$max = $int1 < $int2 ? $int2 : $int1;
140140
return mt_rand($min, $max);
141141
}
142+
143+
/**
144+
* Returns the passed value
145+
*
146+
* @param mixed $value
147+
*
148+
* @return mixed
149+
*/
150+
public static function passthrough($value)
151+
{
152+
return $value;
153+
}
142154

143155
/**
144156
* Returns a random letter from a to z

0 commit comments

Comments
 (0)