13
13
use Faker \Core \Extension \FileExtension ;
14
14
use Faker \Core \Extension \GeneratorAwareExtension ;
15
15
use Faker \Core \Extension \NumberExtension ;
16
- use Faker \Core \Extension \UuidExtension ;
17
16
use Faker \Core \Extension \VersionExtension ;
17
+ use Faker \Core \Generator \ChanceGenerator ;
18
+ use Faker \Core \Generator \UniqueGenerator ;
19
+ use Faker \Core \Generator \ValidGenerator ;
18
20
19
21
/**
20
22
* @mixin BarcodeExtension
24
26
* @mixin FileExtension
25
27
* @mixin NumberExtension
26
28
* @mixin VersionExtension
27
- * @mixin UuidExtension
28
29
*/
29
- class Generator
30
+ class DefaultGenerator
30
31
{
31
32
protected array $ formatters = [];
32
33
@@ -38,13 +39,12 @@ public function __construct(ContainerInterface $container = null)
38
39
}
39
40
40
41
/**
41
- * @template T of Extension\Extension
42
+ * @template T of \Faker\Core\ Extension\Extension
42
43
*
43
44
* @param class-string<T> $id
44
45
*
45
46
* @return T
46
47
* @throws ExtensionNotFound
47
- *
48
48
*/
49
49
public function ext (string $ id ): Extension
50
50
{
@@ -74,17 +74,17 @@ public function ext(string $id): Extension
74
74
* </code>
75
75
*
76
76
* @param bool $reset If set to true, resets the list of existing values
77
- * @param int $maxRetries Maximum number of retries to find a unique value,
77
+ * @param int $retries Maximum number of retries to find a unique value,
78
78
* After which an OverflowException is thrown.
79
79
*
80
80
* @return self A proxy class returning only non-existing values
81
81
* @throws \OverflowException When no unique value can be found by iterating $maxRetries times
82
82
*
83
83
*/
84
- public function unique ($ reset = false , $ maxRetries = 10000 )
84
+ public function unique (bool $ reset = false , int $ retries = 10000 )
85
85
{
86
86
if ($ reset || $ this ->uniqueGenerator === null ) {
87
- $ this ->uniqueGenerator = new UniqueGenerator ($ this , $ maxRetries );
87
+ $ this ->uniqueGenerator = new UniqueGenerator ($ this , $ retries );
88
88
}
89
89
90
90
return $ this ->uniqueGenerator ;
@@ -117,7 +117,7 @@ public function optional(float $weight = 0.5, $default = null)
117
117
* $values []= $faker->valid($evenValidator)->randomDigit;
118
118
* }
119
119
* print_r($values); // [0, 4, 8, 4, 2, 6, 0, 8, 8, 6]
120
- * </code>
120
+ * </code>a
121
121
*
122
122
* @param ?\Closure $validator A function returning true for valid values
123
123
* @param int $maxRetries Maximum number of retries to find a valid value,
@@ -151,7 +151,7 @@ public function format($format, $arguments = [])
151
151
*
152
152
* @return callable
153
153
*/
154
- public function getFormatter ($ format ): callable
154
+ public function getFormatter (string $ format ): callable
155
155
{
156
156
if (isset ($ this ->formatters [$ format ])) {
157
157
return $ this ->formatters [$ format ];
@@ -180,7 +180,7 @@ public function getFormatter($format): callable
180
180
*
181
181
* @return string
182
182
*/
183
- public function parse ($ string )
183
+ public function parse (string $ string ): string
184
184
{
185
185
$ callback = function ($ matches ) {
186
186
return $ this ->format ($ matches [1 ]);
@@ -189,4 +189,18 @@ public function parse($string)
189
189
return preg_replace_callback ('/{{\s?(\w+|[\w \\\]+->\w+?)\s?}}/u ' , $ callback , $ string );
190
190
}
191
191
192
+ public function __call (string $ name , array $ arguments )
193
+ {
194
+ return $ this ->format ($ name , $ arguments );
195
+ }
196
+
197
+ public function __destruct ()
198
+ {
199
+ $ this ->seed ();
200
+ }
201
+
202
+ public function __wakeup (): void
203
+ {
204
+ $ this ->formatters = [];
205
+ }
192
206
}
0 commit comments