作者:xuji
项目:ucloud-ufile-storag
/**
* 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]);
}
作者:laerciobernard
项目:CodeDeliver
/**
* @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;
}
作者:syntropysoftwar
项目:cryptoffice-fronten
/**
* {@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);
}
作者:codixo
项目:flysystem-google-storag
/**
* 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;
}
作者:pkdevbox
项目:filesyste
/**
* {@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;
}
作者:apollop
项目:flysystem-aliyun-os
/**
* 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);
}
作者:njohns-pica
项目:flysystem-vf
/**
* {@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;
}
作者:iwillhappy131
项目:laravel-admi
/**
* 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;
}
}
作者:honeybe
项目:honeybe
/**
* {@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');
}
作者:uaudi
项目:magento-filestorag
/**
* 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;
}
作者:wasa
项目:GaeSupportL
/**
* {@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');
}
作者:mechik
项目:staff-octobe
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'));
}
作者:patrickros
项目:flysystem-redi
/**
* 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');
}
作者:rokd
项目:flysystem-local-database-adapte
/**
* 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');
}
作者:jiii
项目:pt
/**
* {@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);
}
作者:janhartiga
项目:flysystem-aws-s3-v
/**
* 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;
}
作者:RyanThompso
项目:flysyste
/**
* 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;
}
作者:lit
项目:flysystem-sa
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;
}
作者:pkdevbox
项目:filesyste
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'));
}
}
}
作者:modelframewor
项目:modelframewor
/**
* 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');
}