diff --git a/src/Kernel.php b/src/Kernel.php index 0416c854d192d5f989dc6b6526334cd03c6538d2..ffa5f98aae3a9cc92b68ba4f5b95692d1c7ae20a 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -92,10 +92,10 @@ final class Kernel { return preg_replace( '/[^\w_]/', '_', implode("_", [ $plugin->get_slug(), $plugin->get_version(), 'container' ]) ); } - private function initialize_container( Plugin $plugin, bool $useCache = true ): Container { + private function initialize_container( Plugin $plugin, bool $use_cache = true ): Container { $original_builder = new DiBuilder(); - if ( $this->is_prod() && $useCache ) { + if ( $this->is_prod() && $use_cache ) { $original_builder->enableCompilation( $this->get_cache_path(), $this->get_container_name( $plugin ) @@ -114,7 +114,12 @@ final class Kernel { try { return $builder->build(); - } catch ( \Exception $e ) { + } catch ( \InvalidArgumentException $e ) { + if ( $use_cache === false ) { + // It means, that saving to disk was not an issue. + throw $e; + } + return $this->initialize_container( $plugin, false ); } }