コード例 #1
0
 /**
  * Write a new file using a stream.
  *
  * @param string   $path
  * @param resource $resource
  * @param Config   $config   Config object
  *
  * @return array|false false on failure file meta data on success
  */
 public function writeStream($path, $resource, Config $config)
 {
     $path = $this->applyPathPrefix($path);
     $params = $config->get('params', null);
     $mime = $config->get('mime', 'application/octet-stream');
     $checkCrc = $config->get('checkCrc', false);
     list($ret, $code) = $this->ufileSdk->put($path, $resource, ['Content-Type' => $mime]);
 }
コード例 #2
0
 /**
  * @inheritdoc
  */
 public function write($path, $contents, Config $config)
 {
     $type = 'file';
     $result = compact('contents', 'type', 'path');
     if ($visibility = $config->get('visibility')) {
         $result['visibility'] = $visibility;
     }
     return $result;
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function write($path, $contents, Config $config)
 {
     $location = $this->applyPathPrefix($path);
     $headers = [];
     if ($config && $config->has('headers')) {
         $headers = $config->get('headers');
     }
     $response = $this->container->uploadObject($location, $contents, $headers);
     return $this->normalizeObject($response);
 }
コード例 #4
0
 /**
  * Returns an array of options from the config.
  *
  * @param Config $config
  * @return array
  */
 protected function getOptionsFromConfig(Config $config)
 {
     $options = [];
     if ($config->has('visibility')) {
         $options['acl'] = $config->get('visibility') === AdapterInterface::VISIBILITY_PUBLIC ? 'publicRead' : 'private';
     }
     if ($config->has('mimetype')) {
         $options['mimetype'] = $config->get('mimetype');
     }
     // TODO: consider other metadata which we can set here
     return $options;
 }
コード例 #5
0
ファイル: Local.php プロジェクト: pkdevboxy/filesystem
 /**
  * {@inheritdoc}
  */
 public function createDir($dirname, Config $config)
 {
     $location = $this->applyPathPrefix($dirname);
     $umask = umask(0);
     $visibility = $config->get('visibility', 'public');
     if (!is_dir($location) && !@mkdir($location, $this->permissionMap['dir'][$visibility], true)) {
         $return = false;
     } else {
         $return = ['path' => $dirname, 'type' => 'dir'];
     }
     umask($umask);
     return $return;
 }
コード例 #6
0
 /**
  * Handle.
  *
  * @param string $path
  * @param string $localFilePath
  * @param array  $config
  * @return bool
  */
 public function handle($path, $localFilePath, array $config = [])
 {
     if (!method_exists($this->filesystem, 'getAdapter')) {
         return false;
     }
     if (!method_exists($this->filesystem->getAdapter(), 'putFile')) {
         return false;
     }
     $config = new Config($config);
     if (method_exists($this->filesystem, 'getConfig')) {
         $config->setFallback($this->filesystem->getConfig());
     }
     return (bool) $this->filesystem->getAdapter()->putFile($path, $localFilePath, $config);
 }
コード例 #7
0
 /**
  * {@inheritdoc}
  */
 public function write($path, $contents, Config $config)
 {
     $location = $this->applyPathPrefix($path);
     $this->ensureDirectory(dirname($location));
     if (($size = file_put_contents($location, $contents)) === false) {
         return false;
     }
     $type = 'file';
     $result = compact('contents', 'type', 'size', 'path');
     if ($visibility = $config->get('visibility')) {
         $result['visibility'] = $visibility;
         $this->setVisibility($path, $visibility);
     }
     return $result;
 }
コード例 #8
0
 /**
  * Write a new file.
  *
  * @param string $path
  * @param string $contents
  * @param Config $config Config object
  *
  * @return array|false false on failure file meta data on success
  */
 public function write($path, $contents, Config $config)
 {
     $auth = $this->getAuth();
     $token = $auth->uploadToken($this->bucket, $path);
     $params = $config->get('params', null);
     $mime = $config->get('mime', 'application/octet-stream');
     $checkCrc = $config->get('checkCrc', false);
     $upload_manager = $this->getUploadManager();
     list($ret, $error) = $upload_manager->put($token, $path, $contents, $params, $mime, $checkCrc);
     if ($error !== null) {
         $this->logQiniuError($error);
         return false;
     } else {
         return $ret;
     }
 }
コード例 #9
0
ファイル: LocalAdapter.php プロジェクト: honeybee/honeybee
 /**
  * {@inheritdoc}
  */
 public function writeStream($path, $resource, Config $config)
 {
     $location = $this->applyPathPrefix($path);
     $this->ensureDirectory(dirname($location));
     $stream = fopen($location, 'wb+');
     if ($stream === false) {
         return false;
     }
     stream_copy_to_stream($resource, $stream);
     if (!fclose($stream)) {
         return false;
     }
     if ($visibility = $config->get('visibility')) {
         $this->setVisibility($path, $visibility);
     }
     return compact('path', 'visibility');
 }
コード例 #10
0
 /**
  * Upload an object.
  *
  * @param        $path
  * @param        $body
  * @param Config $config
  *
  * @return array
  */
 protected function upload($path, $body, Config $config)
 {
     $key = $this->applyPathPrefix($path);
     $mimetype = MimeType::detectByFileExtension(pathinfo($path, PATHINFO_EXTENSION));
     $config->set('mimetype', $mimetype);
     $return = parent::upload($path, $body, $config);
     if (function_exists('getimagesizefromstring') && strpos($mimetype, 'image') !== false) {
         if (is_resource($body)) {
             rewind($body);
             $size = getimagesizefromstring(stream_get_contents($body));
         } else {
             $size = getimagesizefromstring($body);
         }
         $this->s3Client->copyObject(['Bucket' => $this->bucket, 'CopySource' => $this->bucket . DS . $key, 'ContentType' => $mimetype, 'Metadata' => ['width' => $size[0], 'height' => $size[1]], 'MetadataDirective' => 'REPLACE', 'Key' => $key]);
     }
     return $return;
 }
コード例 #11
0
ファイル: GaeAdapter.php プロジェクト: wasay/GaeSupportL5
 /**
  * {@inheritdoc}
  */
 public function writeStream($path, $resource, Config $config)
 {
     $location = $this->applyPathPrefix($path);
     $this->ensureDirectory(dirname($location));
     if (!($stream = fopen($location, 'w'))) {
         return false;
     }
     while (!feof($resource)) {
         fwrite($stream, fread($resource, 1024), 1024);
     }
     if (!fclose($stream)) {
         return false;
     }
     if ($visibility = $config->get('visibility')) {
         $this->setVisibility($path, $visibility);
     }
     return compact('path', 'visibility');
 }
コード例 #12
0
ファイル: ConfigTests.php プロジェクト: mechiko/staff-october
 public function testGet()
 {
     $config = new Config();
     $this->assertFalse($config->has('setting'));
     $this->assertNull($config->get('setting'));
     $config->set('setting', 'value');
     $this->assertEquals('value', $config->get('setting'));
     $fallback = new Config(['fallback_setting' => 'fallback_value']);
     $config->setFallback($fallback);
     $this->assertEquals('fallback_value', $config->get('fallback_setting'));
 }
コード例 #13
0
 /**
  * Write a new file.
  *
  * @param string $path
  * @param string $contents
  * @param Config $config   Config object
  *
  * @return array|false false on failure file meta data on success
  */
 public function write($path, $contents, Config $config)
 {
     if ($config->has('ttl') && !$config->has('expirationType')) {
         $config->set('expirationType', self::EXPIRE_IN_SECONDS);
     }
     $args = array_merge([$path, $contents], array_filter([$config->get('expirationType'), $config->get('ttl'), $config->get('setFlag')], function ($value) {
         return !is_null($value);
     }));
     if (!call_user_func_array([$this->client, 'set'], $args)) {
         return false;
     }
     return compact('path', 'contents');
 }
コード例 #14
0
 /**
  * Write a new file using a stream.
  *
  * @param string $path
  * @param resource $resource
  * @param Config $config Config object
  *
  * @return array|false false on failure file meta data on success
  */
 public function writeStream($path, $resource, Config $config)
 {
     $model = $this->findByLocation($path);
     if (null === $model) {
         $model = $this->model->create(['location' => $path]);
     }
     while (!feof($resource)) {
         $model->content .= fread($resource, 1024);
     }
     if ($visibility = $config->get('visibility')) {
         $model->visibility = $visibility === true;
     }
     try {
         $model->save();
     } catch (\Exception $e) {
         return false;
     }
     return compact('path', 'visibility');
 }
コード例 #15
0
ファイル: RackspaceAdapter.php プロジェクト: jiiis/ptn
 /**
  * {@inheritdoc}
  */
 public function createDir($dirname, Config $config)
 {
     $headers = $config->get('headers', []);
     $headers['Content-Type'] = 'application/directory';
     $extendedConfig = (new Config())->setFallback($config);
     $extendedConfig->set('headers', $headers);
     return $this->write($dirname, '', $extendedConfig);
 }
コード例 #16
0
 /**
  * Get options from the config.
  *
  * @param Config $config
  *
  * @return array
  */
 protected function getOptionsFromConfig(Config $config)
 {
     $options = $this->options;
     if ($visibility = $config->get('visibility')) {
         // For local reference
         $options['visibility'] = $visibility;
         // For external reference
         $options['ACL'] = $visibility === AdapterInterface::VISIBILITY_PUBLIC ? 'public-read' : 'private';
     }
     if ($mimetype = $config->get('mimetype')) {
         // For local reference
         $options['mimetype'] = $mimetype;
         // For external reference
         $options['ContentType'] = $mimetype;
     }
     foreach (static::$metaOptions as $option) {
         if (!$config->has($option)) {
             continue;
         }
         $options[$option] = $config->get($option);
     }
     return $options;
 }
コード例 #17
0
ファイル: Filesystem.php プロジェクト: RyanThompson/flysystem
 /**
  * Convert a config array to a Config object with the correct fallback.
  *
  * @param array $config
  *
  * @return Config
  */
 protected function prepareConfig(array $config)
 {
     $config = new Config($config);
     $config->setFallback($this->config);
     return $config;
 }
コード例 #18
0
ファイル: KvdbAdapter.php プロジェクト: litp/flysystem-sae
 protected function kvPut($path, $contents, Config $config, $file = null)
 {
     $addOrSet = is_null($file) ? 'set' : 'add';
     $file['contents'] = $contents;
     $file['timestamp'] = time();
     $file['size'] = Util::contentSize($contents);
     if ($visibility = $config->get('visibility')) {
         $file['visibility'] = $visibility;
     }
     if ($this->client->{$addOrSet}($path, $file)) {
         return $file + compact('path');
     }
     return false;
 }
コード例 #19
0
ファイル: Filesystem.php プロジェクト: pkdevboxy/filesystem
 private function doMirror($originDir, $targetDir, Flysystem\Config $config)
 {
     if ($config->get('delete', true) && $this->doHas($targetDir)) {
         $it = $this->getIterator($targetDir, \RecursiveIteratorIterator::CHILD_FIRST);
         foreach ($it as $handler) {
             /** @var HandlerInterface $handler */
             $origin = str_replace($targetDir, $originDir, $handler->getPath());
             if (!$this->doHas($origin)) {
                 if ($handler->isDir()) {
                     $this->doDeleteDir($handler->getPath());
                 } else {
                     $this->doDelete($handler->getPath());
                 }
             }
         }
     }
     if ($this->doHas($originDir)) {
         $this->doCreateDir($targetDir, $config);
     }
     $it = $this->getIterator($originDir, \RecursiveIteratorIterator::SELF_FIRST);
     foreach ($it as $handler) {
         $target = str_replace($originDir, $targetDir, $handler->getPath());
         if ($handler->isDir()) {
             $this->doCreateDir($target, $config);
         } else {
             $this->doCopy($handler->getPath(), $target, $config->get('override'));
         }
     }
 }
コード例 #20
0
 /**
  * Update a file
  *
  * @param   string $path
  * @param   string $contents
  * @param   mixed $config Config object or visibility setting
  * @return  array|bool
  */
 public function update($path, $contents, Config $config)
 {
     $path = $this->clean($path);
     if (!$this->has($path)) {
         throw new \Exception('File not found' . $path);
     }
     $postData = ["file" => '/' . $path, 'content' => $contents, '_method' => 'put'];
     $this->request('put_content', $path, $postData);
     $size = strlen($contents);
     $mimetype = $this->getMimetype($path);
     if ($visibility = $config->get('visibility')) {
         $result['visibility'] = $visibility;
         $this->setVisibility($path, $visibility);
     }
     return compact('path', 'size', 'contents', 'mimetype');
 }
コード例 #21
0
ファイル: AzureAdapter.php プロジェクト: mat33470/PFA
 /**
  * Retrieve options from a Config instance.
  *
  * @param Config $config
  *
  * @return CreateBlobOptions
  */
 protected function getOptionsFromConfig(Config $config)
 {
     $options = new CreateBlobOptions();
     foreach (static::$metaOptions as $option) {
         if (!$config->has($option)) {
             continue;
         }
         call_user_func([$options, "set{$option}"], $config->get($option));
     }
     if ($mimetype = $config->get('mimetype')) {
         $options->setContentType($mimetype);
     }
     return $options;
 }
コード例 #22
0
 public function write($path, $contents, Config $config, $isPutFile = false)
 {
     $token = $this->getToken($path);
     $params = $config->get('params', null);
     $mime = $config->get('mime', 'application/octet-stream');
     $checkCrc = $config->get('checkCrc', false);
     $uploadMgr = $this->getUploadManager();
     if ($isPutFile) {
         list($ret, $error) = $uploadMgr->putFile($token, $path, $contents, $params, $mime, $checkCrc);
     } else {
         list($ret, $error) = $uploadMgr->put($token, $path, $contents, $params, $mime, $checkCrc);
     }
     return $this->returnDeal($ret, $error);
 }
コード例 #23
0
 /**
  * Get options from the config.
  *
  * @param Config $config
  * @return array
  */
 protected function getOptionsFromConfig(Config $config)
 {
     $options = $this->options;
     foreach (static::$mappingOptions as $option => $ossOption) {
         if (!$config->has($option)) {
             continue;
         }
         $options[$ossOption] = $config->get($option);
     }
     return $options;
 }
コード例 #24
0
 /**
  * {@inheritdoc}
  */
 public function createDir($dirname, Config $config)
 {
     $info = $this->getPathInfo($dirname);
     $status = ['path' => $info['path'], 'type' => 'dir', 'visibility' => $config->get('visibility', 'public'), 'timestamp' => time()];
     if (!$this->has($info['path'])) {
         if (!$this->ensurePathExists($info['dirname'], $config) || !($this->redis->hsetnx($this->applyPathPrefix($info['path']), '.', json_encode($status)) && $this->redis->hsetnx($this->applyPathPrefix($info['dirname']), $info['basename'], json_encode($status)))) {
             $status = false;
         }
     } elseif ($this->getMetadata($info['path'])['type'] === 'file') {
         $status = false;
     }
     return $status;
 }
コード例 #25
0
ファイル: PdoAdapter.php プロジェクト: phlib/flysystem-pdo
 /**
  * @return string
  */
 protected function getTempFilename()
 {
     $pid = getmypid();
     $tempDir = $this->config->get('temp_dir');
     return $tempDir . DIRECTORY_SEPARATOR . uniqid("flysystempdo-{$pid}-", true);
 }
コード例 #26
0
 protected function defaultConfig()
 {
     $config = new Config();
     $config->setFallback($this->filesystem->getConfig());
     return $config;
 }
コード例 #27
0
 /**
  * {@inheritdoc}
  */
 public function write($path, $contents, Config $config)
 {
     $location = $this->applyPathPrefix($path);
     $this->client->request('PUT', $location, $contents);
     $result = compact('path', 'contents');
     if ($config->get('visibility')) {
         throw new LogicException(__CLASS__ . ' does not support visibility settings.');
     }
     return $result;
 }
コード例 #28
0
 /**
  * Upload|Update item
  *
  * @param string $path
  * @param string|resource $contents
  * @param Config $config
  *
  * @return array|false item info array
  */
 protected function upload($path, $contents, Config $config)
 {
     list($parentId, $fileName) = $this->splitPath($path);
     $mode = 'update';
     $mime = $config->get('mimetype');
     $srcFile = $this->getFileObject($path);
     $file = new Google_Service_Drive_DriveFile();
     if (!$srcFile) {
         $mode = 'insert';
         $file->setName($fileName);
         $file->setParents([$parentId]);
     }
     $isResource = false;
     if (is_resource($contents)) {
         $fstat = @fstat($contents);
         if (!empty($fstat['size'])) {
             $isResource = true;
         }
         if (!$isResource) {
             $contents = stream_get_contents($contents);
         }
     }
     if ($isResource) {
         // set chunk size (max: 100MB)
         $chunkSizeBytes = 100 * 1024 * 1024;
         $memory = $this->getIniBytes('memory_limit');
         if ($memory) {
             $chunkSizeBytes = min([$chunkSizeBytes, intval($memory / 4 / 256) * 256]);
         }
         if ($fstat['size'] < $chunkSizeBytes) {
             $isResource = false;
             $contents = stream_get_contents($contents);
         }
     }
     if (!$mime) {
         $mime = Util::guessMimeType($fileName, $isResource ? '' : $contents);
     }
     $file->setMimeType($mime);
     if ($isResource) {
         $client = $this->service->getClient();
         // Call the API with the media upload, defer so it doesn't immediately return.
         $client->setDefer(true);
         if ($mode === 'insert') {
             $request = $this->service->files->create($file, ['fields' => self::FETCHFIELDS_GET]);
         } else {
             $request = $this->service->files->update($srcFile->getId(), $file, ['fields' => self::FETCHFIELDS_GET]);
         }
         // Create a media file upload to represent our upload process.
         $media = new Google_Http_MediaFileUpload($client, $request, $mime, null, true, $chunkSizeBytes);
         $media->setFileSize($fstat['size']);
         // Upload the various chunks. $status will be false until the process is
         // complete.
         $status = false;
         $handle = $contents;
         while (!$status && !feof($handle)) {
             // read until you get $chunkSizeBytes from TESTFILE
             // fread will never return more than 8192 bytes if the stream is read buffered and it does not represent a plain file
             // An example of a read buffered file is when reading from a URL
             $chunk = $this->readFileChunk($handle, $chunkSizeBytes);
             $status = $media->nextChunk($chunk);
         }
         // The final value of $status will be the data from the API for the object
         // that has been uploaded.
         if ($status != false) {
             $obj = $status;
         }
         $client->setDefer(false);
     } else {
         $params = ['data' => $contents, 'uploadType' => 'media', 'fields' => self::FETCHFIELDS_GET];
         if ($mode === 'insert') {
             $obj = $this->service->files->create($file, $params);
         } else {
             $obj = $this->service->files->update($srcFile->getId(), $file, $params);
         }
     }
     if ($obj instanceof Google_Service_Drive_DriveFile) {
         $this->cacheFileObjects[$obj->getId()] = $obj;
         if ($mode === 'insert') {
             $this->cacheFileObjects[$fileName] = $obj;
         }
         $result = $this->normaliseObject($obj, Util::dirname($path));
         if ($visibility = $config->get('visibility')) {
             if ($this->setVisibility($path, $visibility)) {
                 $result['visibility'] = $visibility;
             }
         }
         return $result;
     }
     return false;
 }
コード例 #29
0
ファイル: Ftp.php プロジェクト: stevedaddy/react
 /**
  * @inheritdoc
  */
 public function writeStream($path, $resource, Config $config)
 {
     $this->ensureDirectory(Util::dirname($path));
     if (!ftp_fput($this->getConnection(), $path, $resource, $this->transferMode)) {
         return false;
     }
     if ($visibility = $config->get('visibility')) {
         $this->setVisibility($path, $visibility);
     }
     return compact('path', 'visibility');
 }
コード例 #30
0
 /**
  * Retrieve options from a Config instance.
  *
  * @param Config $config
  *
  * @return array
  */
 protected function getOptionsFromConfig(Config $config)
 {
     $options = [];
     foreach (static::$metaOptions as $option) {
         if (!$config->has($option)) {
             continue;
         }
         $options[$option] = $config->get($option);
     }
     if ($mimetype = $config->get('mimetype')) {
         // For local reference
         $options['mimetype'] = $mimetype;
         // For external reference
         $options['ContentType'] = $mimetype;
     }
     return $options;
 }