. */ namespace Doctrine\Common\Cache; /** * Php file cache driver. * * @since 2.3 * @author Fabio B. Silva */ class PhpFileCache extends FileCache { const EXTENSION = '.doctrinecache.php'; /** * {@inheritdoc} */ protected $extension = self::EXTENSION; /** * {@inheritdoc} */ protected function doFetch($id) { $filename = $this->getFilename($id); if ( ! file_exists($filename)) { return false; } $value = include $filename; if ($value['lifetime'] !== 0 && $value['lifetime'] < time()) { return false; } return $value['data']; } /** * {@inheritdoc} */ protected function doContains($id) { $filename = $this->getFilename($id); if ( ! file_exists($filename)) { return false; } $value = include $filename; return $value['lifetime'] === 0 || $value['lifetime'] > time(); } /** * {@inheritdoc} */ protected function doSave($id, $data, $lifeTime = 0) { if ($lifeTime > 0) { $lifeTime = time() + $lifeTime; } if (is_object($data) && ! method_exists($data, '__set_state')) { throw new \InvalidArgumentException( "Invalid argument given, PhpFileCache only allows objects that implement __set_state() " . "and fully support var_export(). You can use the FilesystemCache to save arbitrary object " . "graphs using serialize()/deserialize()." ); } $filename = $this->getFilename($id); $filepath = pathinfo($filename, PATHINFO_DIRNAME); if ( ! is_dir($filepath)) { mkdir($filepath, 0777, true); } $value = array( 'lifetime' => $lifeTime, 'data' => $data ); $value = var_export($value, true); $code = sprintf('