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:  * PHP OpenCloud library.
  4:  * 
  5:  * @copyright 2013 Rackspace Hosting, Inc. See LICENSE for information.
  6:  * @license   https://www.apache.org/licenses/LICENSE-2.0
  7:  * @author    Jamie Hannaford <jamie.hannaford@rackspace.com>
  8:  * @author    Glen Campbell <glen.campbell@rackspace.com>
  9:  */
 10: 
 11: namespace OpenCloud\ObjectStore\Upload;
 12: 
 13: use Guzzle\Http\Message\Response;
 14: use Guzzle\Http\Url;
 15: use OpenCloud\Common\Constants\Header;
 16: use OpenCloud\Common\Constants\Mime;
 17: 
 18: /**
 19:  * Represents an individual part of the EntityBody being uploaded.
 20:  *
 21:  * @codeCoverageIgnore
 22:  */
 23: class TransferPart
 24: {
 25:     /**
 26:      * @var int Its position in the upload queue.
 27:      */
 28:     protected $partNumber;
 29:     
 30:     /**
 31:      * @var string This upload's ETag checksum.
 32:      */
 33:     protected $eTag;
 34:     
 35:     /**
 36:      * @var int The length of this upload in bytes.
 37:      */
 38:     protected $contentLength;
 39:     
 40:     /**
 41:      * @var string The API path of this upload.
 42:      */
 43:     protected $path;
 44: 
 45:     /**
 46:      * @param int $contentLength
 47:      * @return $this
 48:      */
 49:     public function setContentLength($contentLength)
 50:     {
 51:         $this->contentLength = $contentLength;
 52:         return $this;
 53:     }
 54: 
 55:     /**
 56:      * @return int
 57:      */
 58:     public function getContentLength()
 59:     {
 60:         return $this->contentLength;
 61:     }
 62: 
 63:     /**
 64:      * @param  string $etag
 65:      * @return $this
 66:      */
 67:     public function setETag($etag)
 68:     {
 69:         $this->etag = $etag;
 70:         return $this;
 71:     }
 72: 
 73:     /**
 74:      * @return string
 75:      */
 76:     public function getETag()
 77:     {
 78:         return $this->etag;
 79:     }
 80: 
 81:     /**
 82:      * @param int $partNumber
 83:      * @return $this
 84:      */
 85:     public function setPartNumber($partNumber)
 86:     {
 87:         $this->partNumber = $partNumber;
 88:         return $this;
 89:     }
 90: 
 91:     /**
 92:      * @return int
 93:      */
 94:     public function getPartNumber()
 95:     {
 96:         return $this->partNumber;
 97:     }
 98: 
 99:     /**
100:      * @param $path
101:      * @return $this
102:      */
103:     public function setPath($path)
104:     {
105:         $this->path = $path;
106:         return $this;
107:     }
108: 
109:     /**
110:      * @return string
111:      */
112:     public function getPath()
113:     {
114:         return $this->path;
115:     }
116:     
117:     /**
118:      * Create the request needed for this upload to the API.
119:      * 
120:      * @param EntityBody $part    The entity body being uploaded
121:      * @param int        $number  Its number/position, needed for name
122:      * @param OpenStack  $client  Client responsible for issuing requests
123:      * @param array      $options Set by the Transfer object
124:      * @return OpenCloud\Common\Http\Request
125:      */
126:     public static function createRequest($part, $number, $client, $options)
127:     {
128:         $name = sprintf('%s/%s/%d', $options['objectName'], $options['prefix'], $number);
129:         $url  = clone $options['containerUrl'];
130:         $url->addPath($name);
131: 
132:         $headers = array(
133:             Header::CONTENT_LENGTH => $part->getContentLength(),
134:             Header::CONTENT_TYPE   => $part->getContentType()
135:         );
136:         
137:         if ($options['doPartChecksum'] === true) {
138:             $headers['ETag'] = $part->getContentMd5();
139:         }
140:         
141:         $request = $client->put($url, $headers, $part);
142:         
143:         if (isset($options['progress'])) {
144:             $request->getCurlOptions()->add('progress', true);
145:             if (is_callable($options['progress'])) {
146:                 $request->getCurlOptions()->add('progressCallback', $options['progress']);
147:             }
148:         }
149: 
150:         return $request;
151:     }
152: 
153:     /**
154:      * Construct a TransferPart from a HTTP response delivered by the API.
155:      *
156:      * @param Response $response
157:      * @param int      $partNumber
158:      * @return TransferPart
159:      */
160:     public static function fromResponse(Response $response, $partNumber = 1)
161:     {
162:         $responseUri = Url::factory($response->getEffectiveUrl());
163:         
164:         $object = new self();
165:         
166:         $object->setPartNumber($partNumber)
167:             ->setContentLength($response->getHeader(Header::CONTENT_LENGTH))
168:             ->setETag($response->getHeader(Header::ETAG))
169:             ->setPath($responseUri->getPath());
170:         
171:         return $object;
172:     }
173:     
174: }
175: 
PHP OpenCloud API API documentation generated by ApiGen 2.8.0