/** * Move node with contents. * * @return self */ public function move($to, $name = null) { if ($name === null) { $name = $this->getBasename(); } $to .= '/' . $name; Directory::ensure(dirname($to)); if (!@rename($this->getPathname(), $to)) { throw new Exception(sprintf('File "%s" cannot be moved to "%s" (%s).', $this->getPathname(), $to, error_get_last()['message'])); } $c = get_class($this); return new $c($to); }
/** * Move uploaded file to directory. * If no new name is speciefied, original file name will be used. * * @param string * @param string * @return self */ public function move($to, $name = null) { if ($this->isMoved) { return parent::move($to, $name); } $name = $name === null ? $this->getOriginalName() : $name; $path = rtrim($to . '/' . $name, '/'); Directory::ensure(dirname($path)); if (!@move_uploaded_file($this->tmp_name, $path)) { throw new Exception\Upload('upload error move', 'global'); } $this->isMoved = true; parent::__construct($path); return $this; }
/** * {@inheritdoc} */ public function save($id, array $data, $ttl) { $file = $this->dir . $id . '.session'; \Vero\Filesystem\Directory::ensure($this->dir); file_put_contents($file, serialize($data), LOCK_EX); }
/** * Install package. * * Listener receives two arguments: * - string $item: relative path to file/directory * - int $status: 0 - ignored, 1 - installed, 2 - overwritten (when forced install) * * @param string $package * @param boolean $force * @param callable $listener */ public function install(Package $package, $force = false, callable $listener = null) { foreach ($package->getFiles() as $item) { $source = new Node($this->baseRepository . $item); $dest = new Node($this->baseInstance . $item); $exists = $dest->exists(); if ($exists && $force) { $status = 2; } elseif (!$exists) { $status = 1; } else { $status = 0; } if ($status > 0) { if (!file_exists($dest->getPath())) { Directory::ensure($dest->getPath()); } $source->getSpecialized()->copy($dest); } if ($listener) { $listener($item, $status); } } }
/** * Construct backend. * If specified directory not exists, backend will try to create it. * * @param string * @param int */ public function __construct($dir, $maxSize = self::K128) { $this->dir = $dir; $this->maxSize = $maxSize; \Vero\Filesystem\Directory::ensure($dir); }