Merge #16642 - Fix #16055 - Disable cache when the file is not writable

Pull-request: #16642
Fixes: #16055

Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
William Desportes 2021-02-14 01:24:10 +01:00
commit f06b342137
No known key found for this signature in database
GPG Key ID: 90A0EF1B8251A889

View File

@ -11,6 +11,7 @@ use function htmlspecialchars;
use function mb_strlen;
use function rawurldecode;
use function sprintf;
use function is_writable;
/**
* Class used to warm up the routing cache and manage routing.
@ -23,9 +24,16 @@ class Routing
$routes = require ROOT_PATH . 'libraries/routes.php';
$cacheDisabled = ($cfg['environment'] ?? '') === 'development';
$cacheFile = CACHE_DIR . 'routes.cache.php';
if (! is_writable($cacheFile)) {
$cacheDisabled = true;
}
return cachedDispatcher($routes, [
'cacheFile' => CACHE_DIR . 'routes.cache.php',
'cacheDisabled' => ($cfg['environment'] ?? '') === 'development',
'cacheFile' => $cacheFile,
'cacheDisabled' => $cacheDisabled,
]);
}