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 \CannotEnableInMemory ;
19
+ use Zenstruck \Foundry \InMemory \InMemoryRepositoryRegistry ;
20
+ use Zenstruck \Foundry \Object \Instantiator ;
18
21
use Zenstruck \Foundry \Persistence \PersistenceManager ;
19
22
20
23
/**
@@ -41,15 +44,18 @@ final class Configuration
41
44
/** @var \Closure():self|self|null */
42
45
private static \Closure |self |null $ instance = null ;
43
46
47
+ private bool $ inMemory = false ;
48
+
44
49
/**
45
50
* @phpstan-param InstantiatorCallable $instantiator
46
51
*/
47
- public function __construct (
48
- public readonly FactoryRegistry $ factories ,
52
+ public function __construct ( // @phpstan-ignore missingType.generics
53
+ public readonly FactoryRegistryInterface $ factories ,
49
54
public readonly Faker \Generator $ faker ,
50
55
callable $ instantiator ,
51
56
public readonly StoryRegistry $ stories ,
52
57
private readonly ?PersistenceManager $ persistence = null ,
58
+ public readonly ?InMemoryRepositoryRegistry $ inMemoryRepositoryRegistry = null ,
53
59
) {
54
60
$ this ->instantiator = $ instantiator ;
55
61
}
@@ -109,4 +115,21 @@ public static function shutdown(): void
109
115
StoryRegistry::reset ();
110
116
self ::$ instance = null ;
111
117
}
118
+
119
+ /**
120
+ * @throws CannotEnableInMemory
121
+ */
122
+ public function enableInMemory (): void
123
+ {
124
+ if (null === $ this ->inMemoryRepositoryRegistry ) {
125
+ throw CannotEnableInMemory::noInMemoryRepositoryRegistry ();
126
+ }
127
+
128
+ $ this ->inMemory = true ;
129
+ }
130
+
131
+ public function isInMemoryEnabled (): bool
132
+ {
133
+ return $ this ->inMemory ;
134
+ }
112
135
}
0 commit comments