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; }
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; }
public function handle(HttpResponse $response) { if ($response->getStatusCode() == 404) { $response->close(); throw OSSExceptionFactory::factory()->create(OSSErrorCode::NO_SUCH_KEY, ResourceManager::getInstance()->getString('NoSuchKey'), $response->getHeader(OSSHeaders::OSS_HEADER_REQUEST_ID)); } }
public function parse(HttpResponse $response, $options) { $xml = $this->getXmlObject($response->getContent()); $result = new InitiateMultipartUploadResult(); $result->setBucketName((string) $xml->Bucket); $result->setKey((string) $xml->Key); $result->setUploadId((string) $xml->UploadId); return $result; }
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; }
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; }
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 handle(HttpResponse $response) { if ($response->isSuccess()) { return; } if (!$response->getContent() || $response->getContentLength() <= 0) { throw OSSExceptionFactory::factory()->createInvalidResponseException('ServerReturnsUnknownError'); } $error = OSSResponseParserFactory::factory()->createErrorParser()->parse($response, null); throw OSSExceptionFactory::factory()->createFromError($error); }
public function parse(HttpResponse $response, $options) { $xml = $this->getXmlObject($response->getContent()); $code = $xml->Code ? (string) $xml->Code : null; $message = $xml->Message ? (string) $xml->Message : null; $requestId = $xml->RequestId ? (string) $xml->RequestId : null; $hostId = $xml->HostId ? (string) $xml->HostId : null; $error = new OSSError(); $error->setCode($code); $error->setRequestId($requestId); $error->setMessage($message); $error->setHostId($hostId); return $error; }
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; }
public function parse(HttpResponse $response, $options) { $xml = $this->getXmlObject($response->getContent()); $accessPolicy = new AccessControlPolicy(); if (isset($xml->Owner)) { $owner = new Owner(); $owner->setId((string) $xml->Owner->ID); $owner->setDisplayName((string) $xml->Owner->DisplayName); $accessPolicy->setOwner($owner); } if (isset($xml->AccessControlList)) { $grants = array(); foreach ($xml->AccessControlList as $access) { $grants[] = (string) $access->Grant; } $accessPolicy->setGrants($grants); } return $accessPolicy; }
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; }
public function sendRequest(HttpRequest $request, ExecutionContext $context) { $response = new HttpResponse($request); try { $coreRequest = $this->buildCoreRequest($request); $coreResponse = $coreRequest->send(); $coreResponse->getBody()->rewind(); $response->setStatusCode($coreResponse->getStatusCode()); $response->setUri($coreRequest->getUrl()); $response->setContent($coreResponse->getBody()->getStream()); // Replace resource of Guzzle Stream to forbidden resource close when Stream is released. $fakedResource = fopen('php://memory', 'r+'); if ($coreResponse->getBody() !== null) { $coreResponse->getBody()->setStream($fakedResource); } // If request has entity, replace resource of Guzzle Stream to forbidden resource close when Stream is released. if ($coreRequest instanceof EntityEnclosingRequest && $coreRequest->getBody() !== null) { $coreRequest->getBody()->setStream($fakedResource); } fclose($fakedResource); for ($iter = $coreResponse->getHeaders()->getIterator(); $iter->valid(); $iter->next()) { $header = $iter->current(); $response->addHeader($header->getName(), (string) $header); } $request->setResponse($response); return $response; } catch (\Exception $e) { $response->close(); throw new ClientException($e->getMessage(), $e); } }
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; }
public function parse(HttpResponse $response, $options) { $putObjectResult = new PutObjectResult(); $putObjectResult->setETag(OSSUtils::trimQuotes($response->getHeader(OSSHeaders::ETAG))); return $putObjectResult; }