* @package Mammut\Storage */ class FileVFS extends StrictObject implements iVFS { private $basedir; public function __construct($basedir) { $this->basedir = $basedir; } protected function buildFileName($prefix, $name) { $prefix = str_replace(['\\','//'], __DS__, $prefix); $dir = $this->basedir .__DS__. $prefix.__DS__.$name; $dir = str_replace(__DS__.__DS__, __DS__, $dir); return $dir; } public function ls($prefix, $start = 0, $max = -1) { } public function store($prefix, $name, $blob) { $path = $this->buildFileName($prefix, $name); $dir = dirname($path); $file = basename($path); if (!file_exists($dir)) mkdir($dir, 0770, true); if (file_exists($path)) throw new IllegalStateException($path.' exists'); if (is_string($blob)) { file_put_contents($path, $blob); return; } elseif ($blob instanceof iOutput) { $fp = fopen($path, 'w', false); while (!$blob->isEOF()) fwrite($fp, $blob->read(65535)); fclose($fp); return; } throw new ImplementationException(); } public function append($prefix, $name, $blob) { throw new ImplementationException(); } public function replace($prefix, $name, $blob) { $path = $this->buildFileName($prefix, $name); if (!file_exists($path)) throw new FileNotFoundException($uuid); if (is_string($blob)) { file_put_contents($path, $blob); return; } elseif ($blob instanceof iOutput) { $fp = fopen($path, 'w', false); while (!$blob->isEOF()) fwrite($fp, $blob->read(65535)); fclose($fp); return; } throw new ImplementationException(); } public function exists($prefix, $name) { $path = $this->buildFileName($prefix, $name); return file_exists($path); } public function get($prefix, $name) { $path = $this->buildFileName($prefix, $name); if (!file_exists($path)) throw new FileNotFoundException($uuid); return file_get_contents($path); } public function getPart($prefix, $name, $start, $lenght) { throw new ImplementationException(); } public function size($prefix, $name) { $path = $this->buildFileName($prefix, $name); if (!file_exists($path)) throw new FileNotFoundException($uuid); return filesize($path); } public function delete($prefix, $name = FALSE) { $path = $this->buildFileName($prefix, $name); if (!file_exists($path)) throw new FileNotFoundException($uuid); unlink($path); } public function isDirectLinkSupported() { throw new ImplementationException(); } public function getDirectLink($prefix, $name) { throw new ImplementationException(); } }