Skip to content

Commit 7ed575e

Browse files
falkenhawkpartikus
authored andcommitted
Use sourceCache if isSupported check passes, otherwise proceed without cache and do not throw an exception
- so that php-di does not break if there is any problem with apcu - instead of having to wrap ContainerBuilder::build() with try...catch block
1 parent f0ca9a0 commit 7ed575e

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/ContainerBuilder.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,8 @@ public function build()
120120
// Mutable definition source
121121
$source->setMutableDefinitionSource(new DefinitionArray([], $autowiring));
122122

123-
if ($this->sourceCache) {
124-
if (!SourceCache::isSupported()) {
125-
throw new \Exception('APCu is not enabled, PHP-DI cannot use it as a cache');
126-
}
123+
// use cache if isSupported check passes, otherwise proceed without cache and do not throw an exception
124+
if ($this->sourceCache && SourceCache::isSupported()) {
127125
// Wrap the source with the cache decorator
128126
$source = new SourceCache($source, $this->sourceCacheNamespace);
129127
}

0 commit comments

Comments
 (0)