/** * {@inheritdoc} */ public function replace($destination) { if (empty($this->name)) { throw new ObjectException("Unable to replace unassigned storage object."); } if (is_string($destination)) { $destination = $this->storage->bucket($destination); } $this->address = $this->bucket->replace($destination, $this->name); $this->bucket = $destination; return $this; }
/** * {@inheritdoc} */ public function replace(BucketInterface $destination, $name) { if ($destination == $this) { return $this->buildAddress($name); } //Internal copying if ($this->getName() == $destination->getName()) { $this->logger()->info("Internal move '{$this->buildAddress($name)}' " . "to '{$destination->buildAddress($name)}' at '{$this->getName()}' server."); $benchmark = $this->benchmark($this->getName(), "replace::{$this->buildAddress($name)}"); try { $this->server()->replace($this, $destination, $name); } finally { $this->benchmark($benchmark); } } else { $this->logger()->info("External move '{$this->getName()}'.'{$this->buildAddress($name)}'" . " to '{$destination->getName()}'.'{$destination->buildAddress($name)}'."); //Copying using temporary stream (buffer) $destination->put($name, $stream = $this->allocateStream($name)); if ($stream->detach()) { //Dropping temporary stream $this->delete($name); } } return $destination->buildAddress($name); }
/** * Generate object headers. * * @param BucketInterface $bucket * @param string $name * @param mixed $source * @return array */ private function createHeaders(BucketInterface $bucket, $name, $source) { if (empty($mimetype = \GuzzleHttp\Psr7\mimetype_from_filename($name))) { $mimetype = self::DEFAULT_MIMETYPE; } $headers = $bucket->getOption('headers', []); if (!empty($maxAge = $bucket->getOption('maxAge', 0))) { //Shortcut $headers['Cache-control'] = 'max-age=' . $bucket->getOption('maxAge', 0) . ', public'; $headers['Expires'] = gmdate('D, d M Y H:i:s T', time() + $bucket->getOption('maxAge', 0)); } return $headers + ['Content-MD5' => base64_encode(md5_file($this->castFilename($source), true)), 'Content-Type' => $mimetype]; }
/** * Get full file location on server including homedir. * * @param BucketInterface $bucket * @param string $name * @return string */ protected function getPath(BucketInterface $bucket, $name) { if (empty($this->options['home'])) { return $this->files->normalizePath($bucket->getOption('directory') . $name); } return $this->files->normalizePath($this->options['home'] . '/' . $bucket->getOption('directory') . $name); }
/** * {@inheritdoc} */ public function replace(BucketInterface $destination, $name) { if ($destination == $this) { return $this->buildAddress($name); } //Internal copying if ($this->getServerID() == $destination->getServerID()) { $this->logger()->info("Internal move '{$this->buildAddress($name)}' " . "to '{$destination->buildAddress($name)}' at '{$this->getServerID()}' server."); $benchmark = $this->benchmark($this->getServerID(), "replace::{$this->buildAddress($name)}"); $this->server()->replace($this, $destination, $name); $this->benchmark($benchmark); } else { $this->logger()->info("External move '{$this->getServerID()}'.'{$this->buildAddress($name)}'" . " to '{$destination->getServerID()}'.'{$destination->buildAddress($name)}'."); $stream = $this->allocateStream($name); $destination->put($name, $stream); $stream->detach() && $this->delete($name); } return $destination->buildAddress($name); }
/** * Refresh file permissions accordingly to container options. * * @param BucketInterface $bucket * @param string $name * @return bool */ protected function refreshPermissions(BucketInterface $bucket, $name) { $mode = $bucket->getOption('mode', FilesInterface::RUNTIME); return ftp_chmod($this->connection, $mode, $this->getPath($bucket, $name)) !== false; }
/** * Create instance of UriInterface based on provided bucket options and storage object name. * * @param BucketInterface $bucket * @param string $name * @return UriInterface * @throws ServerException */ protected function buildUri(BucketInterface $bucket, $name) { if (empty($bucket->getOption('region'))) { throw new ServerException("Every rackspace container should have specified region."); } $region = $bucket->getOption('region'); if (!isset($this->regions[$region])) { throw new ServerException("'{$region}' region is not supported by Rackspace."); } return new Uri($this->regions[$region] . '/' . $bucket->getOption('container') . '/' . rawurlencode($name)); }
/** * Get valid gridfs collection associated with container. * * @param BucketInterface $bucket Bucket instance. * @return \MongoGridFS */ protected function gridFS(BucketInterface $bucket) { $gridFs = $this->database->getGridFS($bucket->getOption('collection')); $gridFs->createIndex(['filename' => 1]); return $gridFs; }