Skip to content

Commit 64c6a36

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 7f8e6e0 commit 64c6a36

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
@@ -125,10 +125,8 @@ public function build()
125125
// Mutable definition source
126126
$source->setMutableDefinitionSource(new DefinitionArray([], $autowiring));
127127

128-
if ($this->sourceCache) {
129-
if (!SourceCache::isSupported()) {
130-
throw new \Exception('APCu is not enabled, PHP-DI cannot use it as a cache');
131-
}
128+
// use cache if isSupported check passes, otherwise proceed without cache and do not throw an exception
129+
if ($this->sourceCache && SourceCache::isSupported()) {
132130
// Wrap the source with the cache decorator
133131
$source = new SourceCache($source, $this->sourceCacheNamespace);
134132
}

0 commit comments

Comments
 (0)