/** * 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); }
/** * 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)); }
/** * 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; }
/** * 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; }