2 namespace TYPO3\CMS\Core\Cache\Backend;
80 $this->useIgBinary = extension_loaded(
'igbinary');
95 public function setCache(\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
$cache)
97 parent::setCache($cache);
98 if (empty($this->temporaryCacheDirectory)) {
105 $codeOrData = $cache instanceof \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend ?
'Code' :
'Data';
107 if (!is_dir($finalCacheDirectory)) {
110 unset($this->temporaryCacheDirectory);
111 $this->cacheDirectory = $finalCacheDirectory;
112 $this->cacheEntryFileExtension = $cache instanceof \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend ?
'.php' :
'';
114 throw new \TYPO3\CMS\Core\Cache\Exception(
'The length of the temporary cache file path "' . $this->cacheDirectory .
'" exceeds the ' .
'maximum path length of ' . (\TYPO3\CMS\Core\Utility\
GeneralUtility::getMaximumPathLength() - 23) .
'. Please consider ' .
'setting the temporaryDirectoryBase option to a shorter path.', 1248710426);
141 $documentRoot = PATH_site;
142 if ($open_basedir = ini_get(
'open_basedir')) {
143 if (TYPO3_OS ===
'WIN') {
156 $basedirs = explode($delimiter, $open_basedir);
157 $cacheDirectoryInBaseDir =
false;
158 foreach ($basedirs as $basedir) {
159 if (TYPO3_OS ===
'WIN') {
160 $basedir = str_replace(
'\\',
'/', $basedir);
162 if ($basedir[strlen($basedir) - 1] !==
'/') {
166 $documentRoot = $basedir;
168 $cacheDirectoryInBaseDir =
true;
172 if (!$cacheDirectoryInBaseDir) {
173 throw new \TYPO3\CMS\Core\Cache\Exception(
'Open_basedir restriction in effect. The directory "' .
$cacheDirectory .
'" is not in an allowed path.');
180 if (TYPO3_OS ===
'WIN') {
181 if (substr(
$cacheDirectory, 0, strlen($documentRoot)) === $documentRoot) {
190 $this->temporaryCacheDirectory = $documentRoot .
$cacheDirectory . $this->cacheIdentifier .
'/';
204 \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($finalCacheDirectory);
205 }
catch (\RuntimeException $e) {
206 throw new \TYPO3\CMS\Core\Cache\Exception(
'The directory "' . $finalCacheDirectory .
'" can not be created.', 1303669848, $e);
208 if (!is_writable($finalCacheDirectory)) {
209 throw new \TYPO3\CMS\Core\Cache\Exception(
'The directory "' . $finalCacheDirectory .
'" is not writable.', 1203965200);
237 public function set($entryIdentifier, $data, array $tags = array(), $lifetime = null)
239 if (!is_string($data)) {
240 throw new \TYPO3\CMS\Core\Cache\Exception\InvalidDataException(
'The specified data is of type "' . gettype($data) .
'" but a string is expected.', 1334756734);
242 if ($entryIdentifier !== basename($entryIdentifier)) {
243 throw new \InvalidArgumentException(
'The specified entry identifier must not contain a path segment.', 1334756735);
245 if ($entryIdentifier ===
'') {
246 throw new \InvalidArgumentException(
'The specified entry identifier must not be empty.', 1334756736);
249 $result = file_put_contents($temporaryCacheEntryPathAndFilename, $data);
250 \TYPO3\CMS\Core\Utility\GeneralUtility::fixPermissions($temporaryCacheEntryPathAndFilename);
251 if ($result ===
false) {
252 throw new \TYPO3\CMS\Core\Cache\Exception(
'The temporary cache file "' . $temporaryCacheEntryPathAndFilename .
'" could not be written.', 1334756737);
255 rename($temporaryCacheEntryPathAndFilename, $cacheEntryPathAndFilename);
256 if ($this->cacheEntryFileExtension ===
'.php') {
269 public function get($entryIdentifier)
271 if ($entryIdentifier !== basename($entryIdentifier)) {
272 throw new \InvalidArgumentException(
'The specified entry identifier must not contain a path segment.', 1334756877);
275 if (!file_exists($pathAndFilename)) {
278 return file_get_contents($pathAndFilename);
289 public function has($entryIdentifier)
291 if ($entryIdentifier !== basename($entryIdentifier)) {
292 throw new \InvalidArgumentException(
'The specified entry identifier must not contain a path segment.', 1334756878);
294 return file_exists($this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension);
306 public function remove($entryIdentifier)
308 if ($entryIdentifier !== basename($entryIdentifier)) {
309 throw new \InvalidArgumentException(
'The specified entry identifier must not contain a path segment.', 1334756960);
311 if ($entryIdentifier ===
'') {
312 throw new \InvalidArgumentException(
'The specified entry identifier must not be empty.', 1334756961);
315 unlink($this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension);
330 \TYPO3\CMS\Core\Utility\GeneralUtility::flushDirectory($this->cacheDirectory,
true);
343 return file_exists($cacheEntryPathAndFilename) ===
false;
365 return file_exists($pathAndFilename) ? array($pathAndFilename) :
false;
379 if ($entryIdentifier !== basename($entryIdentifier)) {
380 throw new \InvalidArgumentException(
'The specified entry identifier must not contain a path segment.', 1282073037);
382 return file_exists($pathAndFilename) ? require_once $pathAndFilename :
false;