Ejemplo n.º 1
0
 protected function getRequest($options)
 {
     $builder = OSSRequestBuilder::factory();
     if (isset($options[OSSOptions::MODIFIED_SINCE_CONSTRAINT])) {
         $builder->addHeader(OSSHeaders::COPY_OBJECT_SOURCE_IF_MODIFIED_SINCE, DateUtils::formatDate($options[OSSOptions::MODIFIED_SINCE_CONSTRAINT]));
     }
     if (isset($options[OSSOptions::UNMODIFIED_SINCE_CONSTRAINT])) {
         $builder->addHeader(OSSHeaders::COPY_OBJECT_SOURCE_IF_UNMODIFIED_SINCE, DateUtils::formatDate($options[OSSOptions::UNMODIFIED_SINCE_CONSTRAINT]));
     }
     if (isset($options[OSSOptions::MATCHING_ETAG_CONSTRAINTS])) {
         $constraints = $options[OSSOptions::MATCHING_ETAG_CONSTRAINTS];
         $builder->addHeader(OSSHeaders::COPY_OBJECT_SOURCE_IF_MATCH, join(', ', $constraints));
     }
     if (isset($options[OSSOptions::NO_MATCHING_ETAG_CONSTRAINTS])) {
         $constraints = $options[OSSOptions::NO_MATCHING_ETAG_CONSTRAINTS];
         $builder->addHeader(OSSHeaders::COPY_OBJECT_SOURCE_IF_NONE_MATCH, join(', ', $constraints));
     }
     $builder->addHeader(OSSHeaders::COPY_OBJECT_SOURCE, "/" . $options[OSSOptions::SOURCE_BUCKET] . "/" . $options[OSSOptions::SOURCE_KEY]);
     if (OSSUtils::containsMetaOptions($options)) {
         $builder->addObjectMetadataHeaders($options);
         $builder->addHeader(OSSHeaders::COPY_OBJECT_METADATA_DIRECTIVE, 'REPLACE');
     } else {
         $builder->addHeader(OSSHeaders::COPY_OBJECT_METADATA_DIRECTIVE, 'COPY');
     }
     return $builder->setEndpoint($options[OSSOptions::ENDPOINT])->setBucket($options[OSSOptions::DEST_BUCKET])->setKey($options[OSSOptions::DEST_KEY])->setMethod(HttpMethods::PUT)->build();
 }
Ejemplo n.º 2
0
 public function parse(HttpResponse $response, $options)
 {
     $result = new UploadPartResult();
     $result->setETag(OSSUtils::trimQuotes($response->getHeader(OSSHeaders::ETAG)));
     $result->setPartNumber($options[OSSOptions::PART_NUMBER]);
     return $result;
 }
Ejemplo n.º 3
0
 public function parse(HttpResponse $response, $options)
 {
     $object = new OSSObject();
     $object->setBucketName($options[OSSOptions::BUCKET]);
     $object->setKey($options[OSSOptions::KEY]);
     if (!$options[OSSOptions::META_ONLY]) {
         $object->setObjectContent($response->getContent());
     }
     foreach ($response->getHeaders() as $key => $value) {
         if ($key == OSSHeaders::LAST_MODIFIED) {
             $object->addMetadata(OSSHeaders::LAST_MODIFIED, DateUtils::parseDate($value));
         } else {
             if ($key == OSSHeaders::CONTENT_LENGTH) {
                 $object->addMetadata(OSSHeaders::CONTENT_LENGTH, (int) $value);
             } else {
                 if ($key == OSSHeaders::ETAG) {
                     $object->addMetadata(OSSHeaders::ETAG, OSSUtils::trimQuotes($value));
                 } else {
                     if (strpos($key, OSSHeaders::OSS_USER_META_PREFIX) === 0) {
                         $key = substr($key, strlen(OSSHeaders::OSS_USER_META_PREFIX));
                         $object->addUserMetadata($key, $value);
                     } else {
                         $object->addMetadata($key, $value);
                     }
                 }
             }
         }
     }
     return $object;
 }
Ejemplo n.º 4
0
 protected function checkOptions($options)
 {
     $options = parent::checkOptions($options);
     AssertUtils::assertSet(array(OSSOptions::BUCKET, OSSOptions::KEY), $options);
     OSSUtils::assertBucketName($options[OSSOptions::BUCKET]);
     OSSUtils::assertObjectKey($options[OSSOptions::KEY]);
     return $options;
 }
Ejemplo n.º 5
0
 public function parse(HttpResponse $response, $options)
 {
     $xml = $this->getXmlObject($response->getContent());
     $lastModified = DateUtils::parseDate((string) $xml->LastModified);
     $eTag = OSSUtils::trimQuotes((string) $xml->ETag);
     $copyObjectResult = new CopyObjectResult();
     $copyObjectResult->setLastModified($lastModified);
     $copyObjectResult->setETag($eTag);
     return $copyObjectResult;
 }
Ejemplo n.º 6
0
 protected function checkOptions($options)
 {
     $options = parent::checkOptions($options);
     AssertUtils::assertSet(array(OSSOptions::BUCKET), $options);
     if (isset($options[OSSOptions::KEY])) {
         unset($options[OSSOptions::KEY]);
     }
     OSSUtils::assertBucketName($options[OSSOptions::BUCKET]);
     return $options;
 }
Ejemplo n.º 7
0
 protected function checkOptions($options)
 {
     $options = parent::checkOptions($options);
     AssertUtils::assertSet(array(OSSOptions::CONTENT, OSSOptions::BUCKET, OSSOptions::KEY, OSSOptions::UPLOAD_ID, OSSOptions::PART_NUMBER, OSSOptions::PART_SIZE), $options);
     OSSUtils::assertBucketName($options[OSSOptions::BUCKET]);
     OSSUtils::assertObjectKey($options[OSSOptions::KEY]);
     AssertUtils::assertNumber($options[OSSOptions::PART_NUMBER], OSSOptions::PART_NUMBER);
     AssertUtils::assertNumber($options[OSSOptions::PART_SIZE], OSSOptions::PART_SIZE);
     return $options;
 }
 public function parse(HttpResponse $response, $options)
 {
     $xml = $this->getXmlObject($response->getContent());
     $result = new CompleteMultipartUploadResult();
     $result->setETag(OSSUtils::trimQuotes((string) $xml->ETag));
     $result->setLocation((string) $xml->Location);
     $result->setBucketName((string) $xml->Bucket);
     $result->setKey((string) $xml->Key);
     return $result;
 }
Ejemplo n.º 9
0
 public function parse(HttpResponse $response, $options)
 {
     $xml = $this->getXmlObject($response->getContent());
     $objectListing = new ObjectListing();
     $name = (string) $xml->Name;
     $prefix = (string) $xml->Prefix ? (string) $xml->Prefix : null;
     $marker = $xml->Marker ? (string) $xml->Marker : null;
     $maxKeys = $xml->MaxKeys ? (int) $xml->MaxKeys : null;
     $delimiter = $xml->Delimiter ? (string) $xml->Delimiter : null;
     $isTruncated = $xml->IsTruncated ? (string) $xml->IsTruncated : null;
     $nextMarker = $xml->NextMarker ? (string) $xml->NextMarker : null;
     if ($isTruncated === 'true') {
         $isTruncated = true;
     } else {
         $isTruncated = false;
     }
     $objectListing->setBucketName($name);
     $objectListing->setPrefix($prefix);
     $objectListing->setMarker($marker);
     $objectListing->setMaxKeys($maxKeys);
     $objectListing->setDelimiter($delimiter);
     $objectListing->setIsTruncated($isTruncated);
     $objectListing->setNextMarker($nextMarker);
     if ($xml->Contents) {
         $objectSummarys = array();
         foreach ($xml->Contents as $content) {
             $objectSummary = new OSSObjectSummary();
             $key = (string) $content->Key;
             $lastModified = DateUtils::parseDate((string) $content->LastModified);
             $eTag = OSSUtils::trimQuotes((string) $content->ETag);
             $size = (int) $content->Size;
             $storageClass = (string) $content->StorageClass;
             $owner = new Owner();
             $owner->setDisplayName((string) $content->Owner->DisplayName);
             $owner->setId((string) $content->Owner->ID);
             $objectSummary->setBucketName($name);
             $objectSummary->setKey($key);
             $objectSummary->setLastModified($lastModified);
             $objectSummary->setETag($eTag);
             $objectSummary->setSize($size);
             $objectSummary->setStorageClass($storageClass);
             $objectSummary->setOwner($owner);
             $objectSummarys[] = $objectSummary;
         }
         $objectListing->setObjectSummarys($objectSummarys);
     }
     if ($xml->CommonPrefixes) {
         $commonPrefixes = array();
         foreach ($xml->CommonPrefixes as $commonPrefix) {
             $commonPrefixes[] = (string) $commonPrefix->Prefix;
         }
         $objectListing->setCommonPrefixes($commonPrefixes);
     }
     return $objectListing;
 }
 private function checkOptions($options)
 {
     AssertUtils::assertSet(array(OSSOptions::BUCKET, OSSOptions::KEY, OSSOptions::EXPIRES), $options);
     OSSUtils::assertBucketName($options[OSSOptions::BUCKET]);
     if (isset($options[OSSOptions::KEY])) {
         OSSUtils::assertObjectKey($options[OSSOptions::KEY]);
     }
     if (!$options[OSSOptions::EXPIRES] instanceof \DateTime) {
         throw new \InvalidArgumentException(OSSOptions::EXPIRES . ' must be instance of \\DateTime');
     }
     $options[OSSOptions::METHOD] = strtoupper($options[OSSOptions::METHOD]);
     return $options;
 }
Ejemplo n.º 11
0
 protected function checkOptions($options)
 {
     $options = parent::checkOptions($options);
     AssertUtils::assertSet(array(OSSOptions::BUCKET, OSSOptions::KEY), $options);
     OSSUtils::assertBucketName($options[OSSOptions::BUCKET]);
     OSSUtils::assertObjectKey($options[OSSOptions::KEY]);
     if (isset($options[OSSOptions::META_ONLY])) {
         if ($options[OSSOptions::META_ONLY]) {
             unset($options[OSSOptions::SAVE_AS]);
         }
     }
     return $options;
 }
 protected function checkOptions($options)
 {
     $options = parent::checkOptions($options);
     AssertUtils::assertSet(array(OSSOptions::BUCKET, OSSOptions::KEY, OSSOptions::UPLOAD_ID, OSSOptions::PART_ETAGS), $options);
     OSSUtils::assertBucketName($options[OSSOptions::BUCKET]);
     OSSUtils::assertObjectKey($options[OSSOptions::KEY]);
     AssertUtils::assertArray($options[OSSOptions::PART_ETAGS], OSSOptions::PART_ETAGS);
     for ($i = 0; $i < count($options[OSSOptions::PART_ETAGS]); $i++) {
         $partETag = $options[OSSOptions::PART_ETAGS][$i];
         AssertUtils::assertArray($partETag, OSSOptions::PART_ETAGS . '.' . $i);
         AssertUtils::assertSet(array(OSSOptions::PART_NUMBER, OSSOptions::ETAG), $partETag);
     }
     return $options;
 }
Ejemplo n.º 13
0
 protected function checkOptions($options)
 {
     $options = parent::checkOptions($options);
     AssertUtils::assertSet(array(OSSOptions::CONTENT, OSSOptions::BUCKET, OSSOptions::KEY), $options);
     OSSUtils::assertBucketName($options[OSSOptions::BUCKET]);
     OSSUtils::assertObjectKey($options[OSSOptions::KEY]);
     if (isset($options[OSSOptions::CONTENT_LENGTH])) {
         AssertUtils::assertNumber($options[OSSOptions::CONTENT_LENGTH], OSSOptions::CONTENT_LENGTH);
     }
     if (is_resource($options[OSSOptions::CONTENT]) && !isset($options[OSSOptions::CONTENT_LENGTH])) {
         throw new \InvalidArgumentException(OSSOptions::CONTENT_LENGTH . ' must be set when the content is a resource.');
     }
     return $options;
 }
Ejemplo n.º 14
0
 protected function checkOptions($options)
 {
     $options = parent::checkOptions($options);
     AssertUtils::assertSet(array(OSSOptions::BUCKET, OSSOptions::KEY, OSSOptions::UPLOAD_ID), $options);
     OSSUtils::assertBucketName($options[OSSOptions::BUCKET]);
     OSSUtils::assertObjectKey($options[OSSOptions::KEY]);
     if (isset($options[OSSOptions::PART_NUMBER_MARKER])) {
         AssertUtils::assertNumber($options[OSSOptions::PART_NUMBER_MARKER], OSSOptions::PART_NUMBER_MARKER);
     }
     if (isset($options[OSSOptions::MAX_PARTS])) {
         AssertUtils::assertNumber($options[OSSOptions::MAX_PARTS], OSSOptions::MAX_PARTS);
     }
     return $options;
 }
Ejemplo n.º 15
0
 public function parse(HttpResponse $response, $options)
 {
     $xml = $this->getXmlObject($response->getContent());
     $partListing = new PartListing();
     $bucket = (string) $xml->Bucket;
     $key = (string) $xml->Key;
     $uploadId = (string) $xml->UploadId;
     $partNumberMarker = $xml->PartNumberMarker ? (int) $xml->PartNumberMarker : null;
     $nextPartNumberMarker = $xml->NextPartNumberMarker ? (int) $xml->NextPartNumberMarker : null;
     $maxParts = $xml->MaxParts ? (int) $xml->MaxParts : null;
     $isTruncated = $xml->IsTruncated ? (string) $xml->IsTruncated : null;
     $storageClass = $xml->StorageClass ? (string) $xml->StorageClass : null;
     if ($isTruncated === 'true') {
         $isTruncated = true;
     } else {
         $isTruncated = false;
     }
     $partListing->setBucketName($bucket);
     $partListing->setKey($key);
     $partListing->setUploadId($uploadId);
     $partListing->setPartNumberMarker($partNumberMarker);
     $partListing->setNextPartNumberMarker($nextPartNumberMarker);
     $partListing->setMaxParts($maxParts);
     $partListing->setIsTruncated($isTruncated);
     $partListing->setStorageClass($storageClass);
     if ($xml->Part) {
         $parts = array();
         foreach ($xml->Part as $part) {
             $parSummary = new PartSummary();
             $parSummary->setPartNumber((int) $part->PartNumber);
             $parSummary->setLastModified(DateUtils::parseDate((string) $part->LastModified));
             $parSummary->setETag(OSSUtils::trimQuotes((string) $part->ETag));
             $parSummary->setSize((int) $part->Size);
             $parts[] = $parSummary;
         }
         $partListing->setParts($parts);
     }
     return $partListing;
 }
Ejemplo n.º 16
0
 public function build()
 {
     AssertUtils::assertString($this->endpoint, 'endpoint');
     // sent request
     $request = new HttpRequest();
     $request->setEndpoint(OSSUtils::buildEndpoint($this->endpoint, $this->bucket));
     if (isset($this->method)) {
         $request->setMethod($this->method);
     }
     $headers = $this->headers;
     // Date
     if (!isset($headers[OSSHeaders::DATE])) {
         $headers[OSSHeaders::DATE] = DateUtils::formatDate(new \DateTime());
     }
     // Content-Type
     if (!isset($headers[OSSHeaders::CONTENT_TYPE])) {
         $headers[OSSHeaders::CONTENT_TYPE] = '';
     }
     if (!isset($headers[OSSHeaders::CONTENT_LENGTH]) && is_string($this->content)) {
         $headers[OSSHeaders::CONTENT_LENGTH] = (string) strlen($this->content);
     }
     foreach ($headers as $key => $value) {
         $request->addHeader($key, $value);
     }
     $parameters = $this->parameters;
     foreach ($parameters as $key => $value) {
         $request->addParameter($key, $value);
     }
     $request->setResourcePath(OSSUtils::buildResourcePath($this->key));
     $request->setContent($this->content);
     $request->setResponseBody($this->responseBody);
     return $request;
 }
Ejemplo n.º 17
0
 public function parse(HttpResponse $response, $options)
 {
     $putObjectResult = new PutObjectResult();
     $putObjectResult->setETag(OSSUtils::trimQuotes($response->getHeader(OSSHeaders::ETAG)));
     return $putObjectResult;
 }