Пример #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();
 }
Пример #2
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;
 }
Пример #3
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;
 }
Пример #4
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;
 }
 public function parse(HttpResponse $response, $options)
 {
     $xml = $this->getXmlObject($response->getContent());
     $multipartUploadsListing = new MultipartUploadsListing();
     $bucket = (string) $xml->Bucket;
     $prefix = (string) $xml->Prefix ? (string) $xml->Prefix : null;
     $keyMarker = (string) $xml->KeyMarker ? (string) $xml->KeyMarker : null;
     $uploadIdMarker = (string) $xml->UploadIdMarker ? (string) $xml->UploadIdMarker : null;
     $nextKeyMarker = (string) $xml->NextKeyMarker ? (string) $xml->NextKeyMarker : null;
     $nextUploadIdMarker = (string) $xml->NextUploadIdMarker ? (string) $xml->NextUploadIdMarker : null;
     $maxUploads = $xml->MaxUploads ? (int) $xml->MaxUploads : null;
     $delimiter = $xml->Delimiter ? (string) $xml->Delimiter : null;
     $isTruncated = $xml->IsTruncated ? (string) $xml->IsTruncated : null;
     if ($isTruncated === 'true') {
         $isTruncated = true;
     } else {
         $isTruncated = false;
     }
     $multipartUploadsListing->setBucketName($bucket);
     $multipartUploadsListing->setPrefix($prefix);
     $multipartUploadsListing->setKeyMarker($keyMarker);
     $multipartUploadsListing->setUploadIdMarker($uploadIdMarker);
     $multipartUploadsListing->setNextKeyMarker($nextKeyMarker);
     $multipartUploadsListing->setNextUploadIdMarker($nextUploadIdMarker);
     $multipartUploadsListing->setMaxUploads($maxUploads);
     $multipartUploadsListing->setIsTruncated($isTruncated);
     $multipartUploadsListing->setDelimiter($delimiter);
     if ($xml->Upload) {
         $uploads = array();
         foreach ($xml->Upload as $upload) {
             $multipartUpload = new MultipartUpload();
             $multipartUpload->setKey((string) $upload->Key);
             $multipartUpload->setUploadId((string) $upload->UploadId);
             $multipartUpload->setInitiated(DateUtils::parseDate((string) $upload->Initiated));
             $uploads[] = $multipartUpload;
         }
         $multipartUploadsListing->setMultipartUploads($uploads);
     }
     if ($xml->CommonPrefixes) {
         $commonPrefixes = array();
         foreach ($xml->CommonPrefixes->Prefix as $commonPrefix) {
             $commonPrefixes[] = (string) $commonPrefix;
         }
         $multipartUploadsListing->setCommonPrefixes($commonPrefixes);
     }
     return $multipartUploadsListing;
 }
Пример #6
0
 public function parse(HttpResponse $response, $options)
 {
     $xml = $this->getXmlObject($response->getContent());
     $buckets = array();
     $owner = $xml->Owner ? new Owner() : null;
     $owner->setId((string) $xml->Owner->ID);
     $owner->setDisplayName((string) $xml->Owner->DisplayName);
     if ($xml->Buckets) {
         foreach ($xml->Buckets->children() as $bucket) {
             $bucketName = (string) $bucket->Name;
             $creationDate = (string) $bucket->CreationDate;
             $bucket = new Bucket($bucketName);
             $bucket->setOwner($owner);
             $bucket->setName($bucketName);
             $bucket->setCreationDate(DateUtils::parseDate($creationDate));
             $buckets[] = $bucket;
         }
     }
     return $buckets;
 }
Пример #7
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;
 }
Пример #8
0
 public static function populateObjectMetadata(&$headers, $options)
 {
     if (isset($options[OSSOptions::CONTENT_DISPOSITION])) {
         $headers[OSSHeaders::CONTENT_DISPOSITION] = $options[OSSOptions::CONTENT_DISPOSITION];
     }
     if (isset($options[OSSOptions::CACHE_CONTROL])) {
         $headers[OSSHeaders::CACHE_CONTROL] = $options[OSSOptions::CACHE_CONTROL];
     }
     if (isset($options[OSSOptions::CONTENT_ENCODING])) {
         $headers[OSSHeaders::CONTENT_ENCODING] = $options[OSSOptions::CONTENT_ENCODING];
     }
     if (isset($options[OSSOptions::CONTENT_TYPE])) {
         $headers[OSSHeaders::CONTENT_TYPE] = $options[OSSOptions::CONTENT_TYPE];
     }
     if (isset($options[OSSOptions::EXPIRES])) {
         $headers[OSSHeaders::EXPIRES] = DateUtils::formatDate($options[OSSOptions::EXPIRES]);
     }
     if (isset($options[OSSOptions::USER_METADATA])) {
         foreach ($options[OSSOptions::USER_METADATA] as $key => $value) {
             $headers[OSSHeaders::OSS_USER_META_PREFIX . strtolower($key)] = $value;
         }
     }
 }
Пример #9
0
 protected function getRequest($options)
 {
     if ($options[OSSOptions::META_ONLY] === true) {
         unset($options[OSSOptions::RANGE]);
         unset($options[OSSOptions::SAVE_AS]);
         unset($options[OSSOptions::RESPONSE_CONTENT_LANGUAGE]);
         unset($options[OSSOptions::RESPONSE_CONTENT_DISPOSITION]);
         unset($options[OSSOptions::RESPONSE_CACHE_CONTROL]);
         unset($options[OSSOptions::RESPONSE_CONTENT_TYPE]);
         unset($options[OSSOptions::RESPONSE_CONTENT_ENDCODING]);
         unset($options[OSSOptions::RESPONSE_EXPIRES]);
     }
     $builder = OSSRequestBuilder::factory();
     if (isset($options[OSSOptions::RANGE])) {
         $range = $options[OSSOptions::RANGE];
         $rangeValue = 'bytes=';
         if ($range[0] == -1) {
             $rangeValue .= '-' . $range[1];
         } else {
             if ($range[1] == -1) {
                 $rangeValue .= $range[0] . '-';
             } else {
                 $rangeValue .= $range[0] . '-' . $range[1];
             }
         }
         $builder->addHeader(OSSHeaders::RANGE, $rangeValue);
     }
     if (isset($options[OSSOptions::MODIFIED_SINCE_CONSTRAINT])) {
         $builder->addHeader(OSSHeaders::GET_OBJECT_IF_MODIFIED_SINCE, DateUtils::formatDate($options[OSSOptions::MODIFIED_SINCE_CONSTRAINT]));
     }
     if (isset($options[OSSOptions::UNMODIFIED_SINCE_CONSTRAINT])) {
         $builder->addHeader(OSSHeaders::GET_OBJECT_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::GET_OBJECT_IF_MATCH, join(', ', $constraints));
     }
     if (isset($options[OSSOptions::NO_MATCHING_ETAG_CONSTRAINTS])) {
         $constraints = $options[OSSOptions::NO_MATCHING_ETAG_CONSTRAINTS];
         $builder->addHeader(OSSHeaders::GET_OBJECT_IF_NONE_MATCH, join(', ', $constraints));
     }
     if (isset($options[OSSOptions::SAVE_AS])) {
         $builder->setResponseBody($options[OSSOptions::SAVE_AS]);
     }
     return $builder->setEndpoint($options[OSSOptions::ENDPOINT])->setBucket($options[OSSOptions::BUCKET])->setKey($options[OSSOptions::KEY])->setMethod($options[OSSOptions::META_ONLY] ? HttpMethods::HEAD : HttpMethods::GET)->addOverrides($options)->build();
 }
Пример #10
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;
 }
Пример #11
0
 /**
  * 获取Expires
  * @return \DateTime|null
  */
 public function getExpires()
 {
     if (!isset($this->metadata[OSSHeaders::EXPIRES])) {
         return null;
     }
     return DateUtils::parseDate($this->metadata[OSSHeaders::EXPIRES]);
 }