예제 #1
0
 /**
  * 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);
 }
예제 #2
0
 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;
 }
예제 #3
0
 /**
  * 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;
 }
예제 #4
0
파일: Zip.php 프로젝트: luoshulin/falcon
 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;
 }
예제 #5
0
 /**
  * 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;
 }
예제 #6
0
 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;
 }
예제 #7
0
 /**
  * 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;
 }
예제 #8
0
파일: Local.php 프로젝트: xamiro-dev/xamiro
 /**
  * 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');
 }
예제 #9
0
 /**
  * Set the config.
  *
  * @param Config|array|null $config
  */
 protected function setConfig($config)
 {
     $this->config = $config ? Util::ensureConfig($config) : null;
 }
예제 #10
0
 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');
 }
예제 #11
0
파일: Sftp.php 프로젝트: luoshulin/falcon
 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');
 }
예제 #12
0
 /**
  * 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;
 }
예제 #13
0
파일: AwsS3.php 프로젝트: xamiro-dev/xamiro
 /**
  * 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);
 }
예제 #14
0
 /**
  * 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);
 }
예제 #15
0
 /**
  * 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);
 }
예제 #16
0
파일: AwsS3.php 프로젝트: luoshulin/falcon
 /**
  * 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);
 }
예제 #17
0
 /**
  * Constructor.
  *
  * @param AdapterInterface $adapter
  * @param Config|array     $config
  */
 public function __construct(AdapterInterface $adapter, $config = null)
 {
     $this->adapter = $adapter;
     $this->config = Util::ensureConfig($config);
 }
예제 #18
0
 /**
  * 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);
 }