@@ -28,6 +28,9 @@ class ObjectGraphGenerator
28
28
/** @var array */
29
29
private $ registry ;
30
30
31
+ /** @var array */
32
+ private $ temporaryRegistry = [];
33
+
31
34
public function __construct (array $ registry = [])
32
35
{
33
36
$ this ->fakerInstance = Factory::create ();
@@ -40,16 +43,18 @@ public function __construct(array $registry = [])
40
43
$ this ->registry = $ registry ;
41
44
}
42
45
43
- public function generateWithSeed (string $ className, int $ seed ): object
46
+ public function generate (string $ className ): object
44
47
{
45
- $ this ->fakerInstance ->seed ($ seed );
46
-
47
48
return $ this ->generateObject ($ className );
48
49
}
49
50
50
- public function generate (string $ className ): object
51
+ public function generateWithTemporaryConfig (string $ className, array $ config ): object
51
52
{
52
- return $ this ->generateObject ($ className );
53
+ $ this ->temporaryRegistry = $ config ;
54
+ $ object = $ this ->generateObject ($ className );
55
+ $ this ->temporaryRegistry = [];
56
+
57
+ return $ object ;
53
58
}
54
59
55
60
/**
@@ -146,11 +151,14 @@ function () use ($argumentName, $className, $type) {
146
151
147
152
private function isInRegistry (string $ key ): bool
148
153
{
149
- return array_key_exists ($ key , $ this ->registry );
154
+ return array_key_exists ($ key , $ this ->temporaryRegistry ) || array_key_exists ( $ key , $ this -> registry );
150
155
}
151
156
152
157
private function getFromRegistry (string $ key )
153
158
{
159
+ if (isset ($ this ->temporaryRegistry [$ key ])) {
160
+ return $ this ->temporaryRegistry [$ key ]($ this , $ this ->fakerInstance );
161
+ }
154
162
return $ this ->registry [$ key ]($ this , $ this ->fakerInstance );
155
163
}
156
164
}
0 commit comments