Esempio n. 1
0
 /**
  * Stores data the specified key
  *
  * @param string $key    The key to be used to store the data.
  * @param mixed  $data   The data to store.
  * @param int    $ttl    The expiration time of the data in seconds if supported by the backend.
  *
  * @throws \YapepBase\Exception\StorageException      On error.
  * @throws \YapepBase\Exception\ParameterException    If TTL is set and not supported by the backend.
  *
  * @return void
  */
 public function set($key, $data, $ttl = 0)
 {
     if ($this->readOnly) {
         throw new StorageException('Trying to write to a read only storage');
     }
     $startTime = microtime(true);
     $fileName = $this->makeFullPath($key);
     try {
         $this->fileHandler->write($fileName, $this->prepareData($key, $data, $ttl));
     } catch (FileException $e) {
         throw new StorageException('Unable to write data to FileStorage (file: ' . $fileName . ' )', 0, $e);
     }
     // Disable potential warnings if unit testing with vfsStream
     $this->fileHandler->changeMode($fileName, $this->fileMode);
     $debugger = Application::getInstance()->getDiContainer()->getDebugger();
     if (!$this->debuggerDisabled && $debugger !== false) {
         $debugger->addItem(new StorageItem('file', 'file.' . $this->currentConfigurationName, StorageItem::METHOD_SET . ' ' . $key . ' for ' . $ttl, $data, microtime(true) - $startTime));
     }
 }