コード例 #1
0
ファイル: OpenCloud.php プロジェクト: piflex/FilesystemBundle
 /**
  * @param string $key
  *
  * @return \OpenCloud\ObjectStore\Resource\DataObject|false
  */
 protected function tryGetObject($key)
 {
     try {
         return $this->container->getObject($key);
     } catch (ObjectNotFoundException $objFetchError) {
         return false;
     }
 }
コード例 #2
0
ファイル: swift.php プロジェクト: pinoniq/core
 public function fopen($path, $mode)
 {
     $path = $this->normalizePath($path);
     switch ($mode) {
         case 'r':
         case 'rb':
             $tmpFile = \OC_Helper::tmpFile();
             self::$tmpFiles[$tmpFile] = $path;
             try {
                 $object = $this->container->getObject($path);
             } catch (ClientErrorResponseException $e) {
                 \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
                 return false;
             } catch (Exception\ObjectNotFoundException $e) {
                 \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
                 return false;
             }
             try {
                 $objectContent = $object->getContent();
                 $objectContent->rewind();
                 $stream = $objectContent->getStream();
                 file_put_contents($tmpFile, $stream);
             } catch (Exceptions\IOError $e) {
                 \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
                 return false;
             }
             return fopen($tmpFile, 'r');
         case 'w':
         case 'wb':
         case 'a':
         case 'ab':
         case 'r+':
         case 'w+':
         case 'wb+':
         case 'a+':
         case 'x':
         case 'x+':
         case 'c':
         case 'c+':
             if (strrpos($path, '.') !== false) {
                 $ext = substr($path, strrpos($path, '.'));
             } else {
                 $ext = '';
             }
             $tmpFile = \OC_Helper::tmpFile($ext);
             \OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
             if ($this->file_exists($path)) {
                 $source = $this->fopen($path, 'r');
                 file_put_contents($tmpFile, $source);
             }
             self::$tmpFiles[$tmpFile] = $path;
             return fopen('close://' . $tmpFile, $mode);
     }
 }
コード例 #3
0
ファイル: swift.php プロジェクト: mnefedov/core
 /**
  * @param string $urn the unified resource name used to identify the object
  * @return resource stream with the read data
  * @throws Exception from openstack lib when something goes wrong
  */
 public function readObject($urn)
 {
     $this->init();
     $object = $this->container->getObject($urn);
     // we need to keep a reference to objectContent or
     // the stream will be closed before we can do anything with it
     /** @var $objectContent \Guzzle\Http\EntityBody * */
     $objectContent = $object->getContent();
     $objectContent->rewind();
     $stream = $objectContent->getStream();
     // save the object content in the context of the stream to prevent it being gc'd until the stream is closed
     stream_context_set_option($stream, 'swift', 'content', $objectContent);
     return $stream;
 }
コード例 #4
0
ファイル: swift.php プロジェクト: olucao/owncloud-core
 /**
  * @param string $urn the unified resource name used to identify the object
  * @return resource stream with the read data
  * @throws Exception from openstack lib when something goes wrong
  */
 public function readObject($urn)
 {
     $this->init();
     $object = $this->container->getObject($urn);
     // we need to keep a reference to objectContent or
     // the stream will be closed before we can do anything with it
     /** @var $objectContent \Guzzle\Http\EntityBody * */
     $objectContent = $object->getContent();
     $objectContent->rewind();
     // directly returning the object stream does not work because the GC seems to collect it, so we need a copy
     $tmpStream = fopen('php://temp', 'r+');
     stream_copy_to_stream($objectContent->getStream(), $tmpStream);
     rewind($tmpStream);
     return $tmpStream;
 }
コード例 #5
0
ファイル: RackspaceAdapter.php プロジェクト: jiiis/ptn
 /**
  * Get an object.
  *
  * @param string $path
  *
  * @return DataObject
  */
 protected function getObject($path)
 {
     $location = $this->applyPathPrefix($path);
     return $this->container->getObject($location);
 }
コード例 #6
0
ファイル: Rackspace.php プロジェクト: luoshulin/falcon
 /**
  * Get an object
  *
  * @param   string  $path
  * @return  DataObject
  */
 protected function getObject($path)
 {
     return $this->container->getObject($path);
 }