15
15
use Zenstruck \Foundry \Exception \FoundryNotBooted ;
16
16
use Zenstruck \Foundry \Exception \PersistenceDisabled ;
17
17
use Zenstruck \Foundry \Exception \PersistenceNotAvailable ;
18
+ use Zenstruck \Foundry \InMemory \InMemoryRepositoryRegistry ;
18
19
use Zenstruck \Foundry \Persistence \PersistenceManager ;
19
20
20
21
/**
@@ -40,15 +41,18 @@ final class Configuration
40
41
41
42
private static ?self $ instance = null ;
42
43
44
+ private bool $ inMemory = false ;
45
+
43
46
/**
44
47
* @param InstantiatorCallable $instantiator
45
48
*/
46
- public function __construct (
47
- public readonly FactoryRegistry $ factories ,
49
+ public function __construct ( // @phpstan-ignore missingType.generics
50
+ public readonly FactoryRegistryInterface $ factories ,
48
51
public readonly Faker \Generator $ faker ,
49
52
callable $ instantiator ,
50
53
public readonly StoryRegistry $ stories ,
51
54
private readonly ?PersistenceManager $ persistence = null ,
55
+ public readonly ?InMemoryRepositoryRegistry $ inMemoryRepositoryRegistry = null ,
52
56
) {
53
57
$ this ->instantiator = $ instantiator ;
54
58
}
@@ -93,17 +97,34 @@ public static function boot(\Closure|self $configuration): void
93
97
{
94
98
self ::$ instance = \is_callable ($ configuration ) ? ($ configuration )() : $ configuration ;
95
99
self ::$ instance ->bootedForDataProvider = false ;
100
+ self ::$ instance ->inMemory = false ;
96
101
}
97
102
98
103
public static function bootForDataProvider (\Closure |self $ configuration ): void
99
104
{
100
105
self ::$ instance = \is_callable ($ configuration ) ? ($ configuration )() : $ configuration ;
101
106
self ::$ instance ->bootedForDataProvider = true ;
107
+ self ::$ instance ->inMemory = false ;
102
108
}
103
109
104
110
public static function shutdown (): void
105
111
{
106
112
StoryRegistry::reset ();
107
113
self ::$ instance = null ;
108
114
}
115
+
116
+ public function enableInMemory (): void
117
+ {
118
+ $ this ->inMemory = true ;
119
+ }
120
+
121
+ public function disableInMemory (): void
122
+ {
123
+ $ this ->inMemory = false ;
124
+ }
125
+
126
+ public function isInMemoryEnabled (): bool
127
+ {
128
+ return $ this ->inMemory ;
129
+ }
109
130
}
0 commit comments