Overview

Namespaces

  • OpenCloud
    • Autoscale
      • Resource
    • CloudMonitoring
      • Exception
      • Resource
    • Common
      • Collection
      • Constants
      • Exceptions
      • Http
        • Message
      • Identity
      • Log
      • Service
    • Compute
      • Constants
      • Exception
      • Resource
    • Database
      • Resource
    • DNS
      • Resource
    • LoadBalancer
      • Resource
    • ObjectStore
      • Constants
      • Exception
      • Resource
      • Upload
    • Orchestration
    • Queues
      • Exception
      • Resource
    • Volume
      • Resource
  • PHP

Classes

  • AbstractTransfer
  • ConcurrentTransfer
  • ConsecutiveTransfer
  • TransferBuilder
  • TransferPart
  • TransferState
  • Overview
  • Namespace
  • Class
  • Tree
  • Download
 1: <?php
 2: /**
 3:  * @copyright Copyright 2012-2013 Rackspace US, Inc. 
 4:   See COPYING for licensing information.
 5:  * @license   https://www.apache.org/licenses/LICENSE-2.0 Apache 2.0
 6:  * @version   1.5.9
 7:  * @author    Glen Campbell <glen.campbell@rackspace.com>
 8:  * @author    Jamie Hannaford <jamie.hannaford@rackspace.com>
 9:  */
10: 
11: namespace OpenCloud\ObjectStore\Upload;
12: 
13: use Guzzle\Http\EntityBody;
14: use Guzzle\Http\ReadLimitEntityBody;
15: use OpenCloud\Common\Constants\Size;
16: 
17: /**
18:  * A transfer type which executes consecutively - i.e. it will upload an entire EntityBody and then move on to the next
19:  * in a linear fashion. There is no concurrency here.
20:  *
21:  * @codeCoverageIgnore
22:  */
23: class ConsecutiveTransfer extends AbstractTransfer
24: {
25:     
26:     public function transfer()
27:     {
28:         while (!$this->entityBody->isConsumed()) {
29:             
30:             if ($this->entityBody->getContentLength() && $this->entityBody->isSeekable()) {
31:                 // Stream directly from the data
32:                 $body = new ReadLimitEntityBody($this->entityBody, $this->partSize, $this->entityBody->ftell());
33:             } else {
34:                 // If not-seekable, read the data into a new, seekable "buffer"
35:                 $body = EntityBody::factory();
36:                 $output = true;
37:                 while ($body->getContentLength() < $this->partSize && $output !== false) {
38:                     // Write maximum of 10KB at a time
39:                     $length = min(10 * Size::KB, $this->partSize - $body->getContentLength());
40:                     $output = $body->write($this->entityBody->read($length));
41:                 }
42:             }
43: 
44:             if ($body->getContentLength() == 0) {
45:                 break;
46:             }
47: 
48:             $request = TransferPart::createRequest(
49:                 $body, 
50:                 $this->transferState->count() + 1,
51:                 $this->client, 
52:                 $this->options
53:             );
54:             
55:             $response = $request->send();
56: 
57:             $this->transferState->addPart(TransferPart::fromResponse($response));
58:         }
59:     }
60:     
61: }
PHP OpenCloud API API documentation generated by ApiGen 2.8.0