17
17
use Zenstruck \Foundry \Exception \FoundryNotBooted ;
18
18
use Zenstruck \Foundry \Exception \PersistenceDisabled ;
19
19
use Zenstruck \Foundry \Exception \PersistenceNotAvailable ;
20
+ use Zenstruck \Foundry \InMemory \CannotEnableInMemory ;
21
+ use Zenstruck \Foundry \InMemory \InMemoryRepositoryRegistry ;
20
22
use Zenstruck \Foundry \Persistence \PersistenceManager ;
21
23
22
24
/**
@@ -43,16 +45,19 @@ final class Configuration
43
45
/** @var \Closure():self|self|null */
44
46
private static \Closure |self |null $ instance = null ;
45
47
48
+ private bool $ inMemory = false ;
49
+
46
50
/**
47
51
* @phpstan-param InstantiatorCallable $instantiator
48
52
*/
49
53
public function __construct (
50
- public readonly FactoryRegistry $ factories ,
54
+ public readonly FactoryRegistryInterface $ factories ,
51
55
public readonly Faker \Generator $ faker ,
52
56
callable $ instantiator ,
53
57
public readonly StoryRegistry $ stories ,
54
58
private readonly ?PersistenceManager $ persistence = null ,
55
59
private readonly ?EventDispatcherInterface $ eventDispatcher = null ,
60
+ public readonly ?InMemoryRepositoryRegistry $ inMemoryRepositoryRegistry = null ,
56
61
) {
57
62
$ this ->instantiator = $ instantiator ;
58
63
}
@@ -131,4 +136,21 @@ public static function shutdown(): void
131
136
StoryRegistry::reset ();
132
137
self ::$ instance = null ;
133
138
}
139
+
140
+ /**
141
+ * @throws CannotEnableInMemory
142
+ */
143
+ public function enableInMemory (): void
144
+ {
145
+ if (null === $ this ->inMemoryRepositoryRegistry ) {
146
+ throw CannotEnableInMemory::noInMemoryRepositoryRegistry ();
147
+ }
148
+
149
+ $ this ->inMemory = true ;
150
+ }
151
+
152
+ public function isInMemoryEnabled (): bool
153
+ {
154
+ return $ this ->inMemory ;
155
+ }
134
156
}
0 commit comments