protected function addDebugListener(AbstractSync $sync, $resource)
 {
     $sync->getEventDispatcher()->addListener(UploadSync::BEFORE_TRANSFER, function (Event $e) use($resource) {
         if ($e['command'] instanceof CommandInterface) {
             $from = $e['command']['Bucket'] . '/' . $e['command']['Key'];
             $to = $e['command']['SaveAs'] instanceof EntityBodyInterface ? $e['command']['SaveAs']->getUri() : $e['command']['SaveAs'];
             fwrite($resource, "Downloading {$from} -> {$to}\n");
         } elseif ($e['command'] instanceof ResumableDownload) {
             $from = $e['command']->getBucket() . '/' . $e['command']->getKey();
             $to = $e['command']->getFilename();
             fwrite($resource, "Resuming {$from} -> {$to}\n");
         }
     });
 }
 protected function addDebugListener(AbstractSync $sync, $resource)
 {
     $sync->getEventDispatcher()->addListener(UploadSync::BEFORE_TRANSFER, function (Event $e) use($resource) {
         $c = $e['command'];
         if ($c instanceof CommandInterface) {
             $uri = $c['Body']->getUri();
             $size = $c['Body']->getSize();
             fwrite($resource, "Uploading {$uri} -> {$c['Key']} ({$size} bytes)\n");
             return;
         }
         // Multipart upload
         $body = $c->getSource();
         $totalSize = $body->getSize();
         $progress = 0;
         fwrite($resource, "Beginning multipart upload: " . $body->getUri() . ' -> ');
         fwrite($resource, $c->getState()->getFromId('Key') . " ({$totalSize} bytes)\n");
         $c->getEventDispatcher()->addListener(AbstractTransfer::BEFORE_PART_UPLOAD, function ($e) use(&$progress, $totalSize, $resource) {
             $command = $e['command'];
             $size = $command['Body']->getContentLength();
             $percentage = number_format($progress / $totalSize * 100, 2);
             fwrite($resource, "- Part {$command['PartNumber']} ({$size} bytes, {$percentage}%)\n");
             $progress += $size;
         });
     });
 }
예제 #3
0
 protected function transferCommands(array $commands)
 {
     parent::transferCommands($this->filterCommands($commands));
 }