81 if (empty($this->temporaryCacheDirectory)) {
90 if (!is_dir($finalCacheDirectory)) {
93 unset($this->temporaryCacheDirectory);
94 $this->cacheDirectory = $finalCacheDirectory;
96 if (strlen($this->cacheDirectory) + 23 > PHP_MAXPATHLEN) {
97 throw new Exception(
'The length of the temporary cache file path "' . $this->cacheDirectory .
'" exceeds the ' .
'maximum path length of ' . (PHP_MAXPATHLEN - 23) .
'. Please consider ' .
'setting the temporaryDirectoryBase option to a shorter path.', 1248710426);
123 if ($open_basedir = ini_get(
'open_basedir')) {
137 $basedirs = explode($delimiter, $open_basedir);
138 $cacheDirectoryInBaseDir =
false;
139 foreach ($basedirs as $basedir) {
141 $basedir = str_replace(
'\\',
'/', $basedir);
143 if ($basedir[strlen($basedir) - 1] !==
'/') {
147 $documentRoot = $basedir;
149 $cacheDirectoryInBaseDir =
true;
153 if (!$cacheDirectoryInBaseDir) {
155 'Open_basedir restriction in effect. The directory "' .
$cacheDirectory .
'" is not in an allowed path.',
165 if (!empty($documentRoot) && strpos(
$cacheDirectory, $documentRoot) === 0) {
186 GeneralUtility::mkdir_deep($finalCacheDirectory);
187 }
catch (\RuntimeException $e) {
188 throw new Exception(
'The directory "' . $finalCacheDirectory .
'" can not be created.', 1303669848, $e);
190 if (!is_writable($finalCacheDirectory)) {
191 throw new Exception(
'The directory "' . $finalCacheDirectory .
'" is not writable.', 1203965200);
216 public function set($entryIdentifier, $data, array $tags = [], $lifetime =
null)
218 if (!is_string($data)) {
219 throw new InvalidDataException(
'The specified data is of type "' . gettype($data) .
'" but a string is expected.', 1334756734);
222 throw new \InvalidArgumentException(
'The specified entry identifier must not contain a path segment.', 1334756735);
224 if ($entryIdentifier ===
'') {
225 throw new \InvalidArgumentException(
'The specified entry identifier must not be empty.', 1334756736);
228 $result = file_put_contents($temporaryCacheEntryPathAndFilename, $data);
229 GeneralUtility::fixPermissions($temporaryCacheEntryPathAndFilename);
230 if ($result ===
false) {
231 throw new Exception(
'The temporary cache file "' . $temporaryCacheEntryPathAndFilename .
'" could not be written.', 1334756737);
234 rename($temporaryCacheEntryPathAndFilename, $cacheEntryPathAndFilename);
235 if ($this->cacheEntryFileExtension ===
'.php') {
236 GeneralUtility::makeInstance(OpcodeCacheService::class)->clearAllActive($cacheEntryPathAndFilename);
247 public function get($entryIdentifier)
250 throw new \InvalidArgumentException(
'The specified entry identifier must not contain a path segment.', 1334756877);
253 if (!file_exists($pathAndFilename)) {
256 return file_get_contents($pathAndFilename);
266 public function has($entryIdentifier)
269 throw new \InvalidArgumentException(
'The specified entry identifier must not contain a path segment.', 1334756878);
271 return file_exists($this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension);
282 public function remove($entryIdentifier)
285 throw new \InvalidArgumentException(
'The specified entry identifier must not contain a path segment.', 1334756960);
287 if ($entryIdentifier ===
'') {
288 throw new \InvalidArgumentException(
'The specified entry identifier must not be empty.', 1334756961);
291 unlink($this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension);
292 }
catch (\Exception $e) {
303 GeneralUtility::flushDirectory($this->cacheDirectory,
true);
315 return file_exists($cacheEntryPathAndFilename) ===
false;
334 return file_exists($pathAndFilename) ? [$pathAndFilename] :
false;
348 throw new \InvalidArgumentException(
'The specified entry identifier must not contain a path segment.', 1282073037);
350 return file_exists($pathAndFilename) ? require_once $pathAndFilename :
false;
360 public function require(
string $entryIdentifier)
364 throw new \InvalidArgumentException(
'The specified entry identifier must not contain a path segment.', 1532528267);
366 return file_exists($pathAndFilename) ? require $pathAndFilename :
false;