Ejemplo n.º 1
0
 /**
  * @param mixed $data Data to be stored
  * @param null|mixed $key Key under which to store the data, is generated if omitted
  * @return string The key
  * @throws \Exception
  */
 public function write($data, $key = null)
 {
     if (!$key) {
         $key = $this->key->generate();
     }
     $this->guardStringiness($key);
     $this->data[(string) $key] = $data;
     return $key;
 }
Ejemplo n.º 2
0
 /**
  * @param string $data Data to be stored
  * @param null|string $key Key under which to store the data, is generated if omitted
  * @return string The key
  * @throws \Exception If data or key are not strings
  */
 public function write($data, $key = null)
 {
     $this->guardStringiness($data, 'Only strings can be stored in flat files.');
     if (!$key) {
         $key = $this->key->generate();
     }
     $this->guardStringiness($key);
     $path = $this->path($key);
     $dir = dirname($path);
     if (!file_exists($dir)) {
         mkdir($dir, 0777, true);
     }
     file_put_contents($path, (string) $data);
     return $key;
 }