コード例 #1
0
 /**
  * @dataProvider  copyProvider
  */
 public function testWriteStream(Copy $adapter, API $mock)
 {
     $mock->shouldReceive('uploadFromStream')->andReturn((object) ['type' => 'file', 'path' => 'something', 'modified_time' => '10 September 2000'], false);
     // generate dummy data file
     $filepath = tempnam(sys_get_temp_dir(), 'copy-unit-test.tmp');
     file_put_contents($filepath, 'copy==');
     $fh = fopen($filepath, 'r');
     $result = $adapter->writeStream('something', $fh, new Config());
     $this->assertInternalType('array', $result);
     $this->assertArrayHasKey('type', $result);
     $this->assertEquals('file', $result['type']);
     $fh = fopen($filepath, 'r');
     $this->assertFalse($adapter->writeStream('something', $fh, new Config()));
 }
コード例 #2
0
ファイル: CopyAdapter.php プロジェクト: hmoritake/xelfinder
 /**
  * Get item absolute URL
  *
  * @param string   $path
  *
  * @return string item absolute URL
  */
 public function getUrl($path)
 {
     $location = $this->applyPathPrefix($path);
     try {
         $object = $this->getMetadata($path);
         if (!isset($object->links)) {
             $this->metaCache[$location] = $object = $this->client->getMeta($location);
         }
         $url = '';
         if (!empty($object->links)) {
             foreach ($object->links as $link) {
                 if ($link->status === 'viewed' && $link->permissions === 'read') {
                     $url = $link->url;
                     break;
                 }
             }
         }
         if ($url === '') {
             $object = $this->client->createLink($location);
             $url = $object->url;
         }
         return $url . '/' . rawurlencode($object->name);
     } catch (\Exception $e) {
         return '';
     }
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function listContents($dirname = '', $recursive = false)
 {
     $listing = [];
     $location = $this->applyPathPrefix($dirname);
     if (!($result = $this->client->listPath($location))) {
         return [];
     }
     foreach ($result as $object) {
         $listing[] = $this->normalizeObject($object, $object->path);
         if ($recursive && $object->type == 'dir') {
             $listing = array_merge($listing, $this->listContents($object->path, $recursive));
         }
     }
     return $listing;
 }
コード例 #4
0
ファイル: Copycom.php プロジェクト: todiadiyatmo/phpbu
 /**
  * (non-PHPDoc)
  *
  * @see    \phpbu\App\Backup\Sync::sync()
  * @param  \phpbu\App\Backup\Target $target
  * @param  \phpbu\App\Result        $result
  * @throws \phpbu\App\Backup\Sync\Exception
  */
 public function sync(Target $target, Result $result)
 {
     $sourcePath = $target->getPathname();
     $targetPath = $this->path . $target->getFilename();
     $copy = new CopycomApi($this->appKey, $this->appSecret, $this->userKey, $this->userSecret);
     try {
         // open a file to upload
         $fh = fopen($sourcePath, 'rb');
         // upload the file in 1MB chunks
         $parts = array();
         while ($data = fread($fh, 1024 * 1024)) {
             $part = $copy->sendData($data);
             array_push($parts, $part);
         }
         fclose($fh);
         // finalize the file
         $copy->createFile($targetPath, $parts);
     } catch (\Exception $e) {
         throw new Exception($e->getMessage(), null, $e);
     }
     $result->debug('upload: done');
 }