diff --git a/src/Supportive/DependencyInjection/ServiceContainerBuilder.php b/src/Supportive/DependencyInjection/ServiceContainerBuilder.php index bf72dc919..9d39447d3 100644 --- a/src/Supportive/DependencyInjection/ServiceContainerBuilder.php +++ b/src/Supportive/DependencyInjection/ServiceContainerBuilder.php @@ -129,11 +129,21 @@ private static function loadServices(ContainerBuilder $container, ?SplFileInfo $ return; } - if (!file_exists($cacheFile->getPathname()) - && !touch($cacheFile->getPathname()) - && !is_writable($cacheFile->getPathname()) - ) { - throw CacheFileException::notWritable($cacheFile); + if (!file_exists($cacheFile->getPathname())) { + $dirname = $cacheFile->getPath() ?: '.'; + + if (!is_dir($dirname) + && mkdir($dirname.'/', 0777, true) + && !is_dir($dirname) + ) { + throw CacheFileException::notWritable($cacheFile); + } + + if (!touch($cacheFile->getPathname()) + && !is_writable($cacheFile->getPathname()) + ) { + throw CacheFileException::notWritable($cacheFile); + } } $container->setParameter('deptrac.cache_file', $cacheFile->getPathname());