/** * Constructor. * * @param AdapterInterface $adapter * @param CacheInterface $cache * @param mixed $config */ public function __construct(AdapterInterface $adapter, CacheInterface $cache = null, $config = null) { $this->adapter = $adapter; $this->cache = $cache ?: new Cache\Memory(); $this->cache->load(); $this->config = Util::ensureConfig($config); }
public function write($path, $contents, $config = null) { $config = Util::ensureConfig($config); $this->client->request('PUT', $path, $contents); $result = compact('path', 'contents'); if ($config && ($visibility = $config->get('visibility'))) { $this->setVisibility($path, $visibility); } return $result; }
/** * Write a file * * @param $path * @param $contents * @param null $config * @return array|bool */ public function write($path, $contents, $config = null) { $type = 'file'; $config = Util::ensureConfig($config); $result = compact('contents', 'type', 'size', 'path'); if ($visibility = $config->get('visibility')) { $result['visibility'] = $visibility; } return $result; }
public function write($path, $contents, $config = null) { $dirname = Util::dirname($path); $config = Util::ensureConfig($config); if (!empty($dirname) && !$this->has($dirname)) { $this->createDir($dirname); } if (!$this->archive->addFromString($path, $contents)) { return false; } $result = compact('path', 'contents'); if ($config && $config->get('visibility')) { throw new LogicException(get_class($this) . ' does not support visibility settings.'); } return $result; }
/** * Update a file with the contents of a stream * * @param string $path * @param resource $resource * @param mixed $config Config object or visibility setting * @return bool success boolean * @throws InvalidArgumentException */ public function updateStream($path, $resource, $config = null) { if (!is_resource($resource)) { throw new InvalidArgumentException(__METHOD__ . ' expects argument #2 to be a valid resource.'); } $path = Util::normalizePath($path); $config = Util::ensureConfig($config); $config->setFallback($this->getConfig()); $this->assertPresent($path); Util::rewindStream($resource); if (!($object = $this->adapter->updateStream($path, $resource, $config))) { return false; } $this->cache->updateObject($path, $object + ['contents' => false], true); return true; }
public function writeStream($path, $resource, $config = null) { $path = Util::normalizePath($path); $this->assertAbsent($path); $config = Util::ensureConfig($config); $config->setFallback($this->getConfig()); if (!is_resource($resource)) { throw new InvalidArgumentException(__METHOD__ . ' expects argument #2 to be a valid resource.'); } if (!($object = $this->adapter->writeStream($path, $resource, $config))) { return false; } $this->cache->updateObject($path, $object, true); $this->cache->ensureParentDirectories($path); return true; }
/** * Upload a file. * * @param string $path * @param string|resource $contents * @param Config $config * @return bool */ public function upload($path, $contents, Config $config) { $connection = $this->getConnection(); $this->ensureDirectory(Util::dirname($path)); $config = Util::ensureConfig($config); if (!$connection->put($path, $contents, SFTP::SOURCE_STRING)) { return false; } if ($config && ($visibility = $config->get('visibility'))) { $this->setVisibility($path, $visibility); } return true; }
/** * Write using a stream * * @param $path * @param $resource * @param null $config * @return array|bool */ public function writeStream($path, $resource, $config = null) { rewind($resource); $config = Util::ensureConfig($config); $location = $this->prefix($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'); }
/** * Set the config. * * @param Config|array|null $config */ protected function setConfig($config) { $this->config = $config ? Util::ensureConfig($config) : null; }
public function writeStream($path, $resource, $config = null) { $this->ensureDirectory(Util::dirname($path)); $config = Util::ensureConfig($config); if (!ftp_fput($this->getConnection(), $path, $resource, $this->transferMode)) { return false; } if ($visibility = $config->get('visibility')) { $this->setVisibility($path, $visibility); } return compact('path', 'visibility'); }
public function write($path, $contents, $config = null) { $connection = $this->getConnection(); $this->ensureDirectory(Util::dirname($path)); $config = Util::ensureConfig($config); if (!$connection->put($path, $contents, NET_SFTP_STRING)) { return false; } if ($config && ($visibility = $config->get('visibility'))) { $this->setVisibility($path, $visibility); } return compact('contents', 'visibility'); }
/** * Write using a stream * * @param $path * @param $resource * @param null $config * @return array|bool */ public function writeStream($path, $resource, Config $config) { $username = '******'; $password = '******'; $auth = base64_encode($username . ':' . $password); $this->client->setUri('http://192.168.10.47/api/wstest/upload/fg'); // $this->client->setUri('http://files.local/api/v2/fs'); $this->client->setMethod('POST'); $headers = ['Accept' => '*/*', 'Cache-Control' => 'no-cache', 'Authorization' => 'Basic ' . $auth, 'X-File-Name' => 'todo.txt', 'Content-Type' => 'application/x-www-form-urlencoded']; $this->client->setHeaders($headers); file_put_contents('tmp', $resource); // $this->client->setFileUpload('todo.txt', 'todo_txt', $resource); $text = 'this is some plain text'; $this->client->setFileUpload('some_text.txt', 'some_text_txt', $text, 'text/plain'); prn($this->client->send()->getContent()); exit; $location = $this->applyPathPrefix($path); $config = Util::ensureConfig($config); $this->ensureDirectory(dirname($location)); $this->client->setMethod('POST'); $this->client->setUri($this->api_url); $this->client->setParameterPOST(array_merge($this->auth_param, ['filename' => $path])); $this->client->setHeaders(['wp_path' => $path]); file_put_contents('tmp', $resource); $this->client->setFileUpload('tmp', 'form'); $response = $this->client->send(); $path = json_decode($response->getContent())->file_id; $type = 'wepo_fs'; $result = compact('contents', 'type', 'size', 'path'); if ($visibility = $config->get('visibility')) { $result['visibility'] = $visibility; } return $result; }
/** * Write using a stream * * @param string $path * @param resource $resource * @param mixed $config * * @return array file metadata */ public function writeStream($path, $resource, $config = null) { $config = Util::ensureConfig($config); $options = $this->getOptions($path, array('Body' => $resource), $config); $this->client->putObject($options); return $this->normalizeObject($options); }
/** * Write a file * * @param string $path * @param string $contents * @param mixed $config * @return array file metadata */ public function write($path, $contents, $config = null) { $mimeType = Util::guessMimeType($path, $contents); if (isset($config)) { if (isset($config["mimeType"])) { $mimeType = $config["mimeType"]; } } $config = Util::ensureConfig($config); $options = $this->getOptions($path, array('ContentType' => $mimeType, 'ContentLength' => Util::contentSize($contents)), $config); $dirname = dirname($path); $filename = basename($path); if ($this->has($path)) { $isUpdate = true; $file = $this->service->files->get($path); } else { $file = new Google_Service_Drive_DriveFile(); $file->setTitle($filename); $file->setMimeType($mimeType); if ($dirname != ".") { $parent = new Google_Service_Drive_ParentReference(); $parent->setId($dirname); $file->setParents(array($parent)); } } if (isset($isUpdate)) { $result = $this->service->files->update($file['id'], $file, array('data' => $contents, 'mimeType' => $mimeType, 'uploadType' => "multipart")); } else { $result = $this->service->files->insert($file, array('data' => $contents, 'mimeType' => $mimeType, 'uploadType' => "multipart")); } if ($result === false) { return false; } $result['mimeType'] = $mimeType; $result['title'] = $filename; $result['id'] = $result->getId(); return $this->normalizeObject($result); }
/** * Write using a stream * * @param string $path * @param resource $resource * @param mixed $config ['visibility'='private', 'mimetype'='', 'Metadata'=[]] * * @return array file metadata */ public function writeStream($path, $resource, $config = null) { $config = Util::ensureConfig($config); $options = array('Body' => $resource); $options['ContentLength'] = Util::getStreamSize($resource); $options = $this->getOptions($path, $options, $config); return $this->writeObject($options); }
/** * Write using a stream * * @param string $path * @param resource $resource * @param mixed $config * * @return array file metadata */ public function writeStream($path, $resource, $config = null) { $config = Util::ensureConfig($config); $options = $this->getOptions($path, array('Body' => $resource)); if ($visibility = $config->get('visibility')) { $options['ACL'] = $visibility === AdapterInterface::VISIBILITY_PUBLIC ? 'public-read' : 'private'; } if ($mimetype = $config->get('mimetype')) { $options['ContentType'] = $mimetype; } $this->client->putObject($options); if ($visibility) { $options['visibility'] = $visibility; } return $this->normalizeObject($options); }
/** * Constructor. * * @param AdapterInterface $adapter * @param Config|array $config */ public function __construct(AdapterInterface $adapter, $config = null) { $this->adapter = $adapter; $this->config = Util::ensureConfig($config); }
/** * Write using a stream * * @param string $path * @param resource $resource * @param mixed $config ['visibility'='private', 'mimetype'='', 'streamsize'=0, 'Metadata'=[]] * * @return array file metadata */ public function writeStream($path, $resource, $config = null) { $config = Util::ensureConfig($config); $options = array('Body' => $resource); $options = $this->getOptions($path, $options, $config); $multipartLimit = $this->mbToBytes($options['Multipart']); // If we don't know the streamsize, we have to assume we need to upload using multipart, otherwise it might fail. if ($config->has('streamsize') === false || $config->get('streamsize') > $multipartLimit) { $result = $this->putObjectMultipart($options); } else { $result = $this->client->putObject($options); } if ($result === false) { return false; } return $this->normalizeObject($options); }