. */ namespace SP\Storage\File; use RuntimeException; /** * Class FileCachePacked * * @package SP\Storage\File; */ final class FileCachePacked extends FileCacheBase { /** * @return mixed * @throws RuntimeException * @throws FileException */ public function load() { $this->path->checkIsReadable(); $dataUnpacked = gzuncompress($this->path->readToString()); if ($dataUnpacked === false) { throw new FileException(sprintf(__('Error while decompressing the file data (%s)'), $this->path->getFile())); } $data = unserialize($dataUnpacked); if ($data === false) { throw new FileException(__('Error while retrieving the data')); } return $data; } /** * @param mixed $data * * @return FileCacheInterface * @throws FileException */ public function save($data): FileCacheInterface { $this->createPath(); $data = gzcompress(serialize($data)); if ($data === false) { throw new FileException(sprintf(__('Error while compressing the file data (%s)'), $this->path->getFile())); } $this->path->checkIsWritable() ->write($data) ->close(); return $this; } }