/** * Creates UpdateEntityResult from HTTP response headers. * * @param array $headers The HTTP response headers. * * @return \MicrosoftAzure\Storage\Table\Models\UpdateEntityResult */ public static function create($headers) { $result = new UpdateEntityResult(); $clean = array_change_key_case($headers); $result->setETag($clean[Resources::ETAG]); return $result; }
/** * @covers MicrosoftAzure\Storage\Table\Models\UpdateEntityResult::setETag * @covers MicrosoftAzure\Storage\Table\Models\UpdateEntityResult::getETag */ public function testSetETag() { // Setup $expected = '0x8CAFB82EFF70C46'; $entity = new UpdateEntityResult(); $entity->setETag($expected); // Test $entity->setETag($expected); // Assert $this->assertEquals($expected, $entity->getETag()); }
/** * Creates BatchResult object. * * @param string $body The HTTP response body. * @param array $operations The batch operations. * @param array $contexts The batch operations context. * @param IAtomReaderWriter $atomSerializer The Atom reader and writer. * @param IMimeReaderWriter $mimeSerializer The MIME reader and writer. * * @return \MicrosoftAzure\Storage\Table\Models\BatchResult * * @throws \InvalidArgumentException */ public static function create($body, $operations, $contexts, $atomSerializer, $mimeSerializer) { $result = new BatchResult(); $responses = self::_constructResponses($body, $mimeSerializer); $callbackName = __CLASS__ . '::_compareUsingContentId'; $count = count($responses); $entries = array(); // Sort $responses based on Content-ID so they match order of $operations. uasort($responses, $callbackName); for ($i = 0; $i < $count; $i++) { $context = $contexts[$i]; $response = $responses[$i]; $operation = $operations[$i]; $type = $operation->getType(); $body = $response->body; $headers = HttpFormatter::formatHeaders($response->headers); try { ServiceRestProxy::throwIfError($response->statusCode, $response->reason, $response->body, $context->getStatusCodes()); switch ($type) { case BatchOperationType::INSERT_ENTITY_OPERATION: $entries[] = InsertEntityResult::create($body, $headers, $atomSerializer); break; case BatchOperationType::UPDATE_ENTITY_OPERATION: case BatchOperationType::MERGE_ENTITY_OPERATION: case BatchOperationType::INSERT_REPLACE_ENTITY_OPERATION: case BatchOperationType::INSERT_MERGE_ENTITY_OPERATION: $entries[] = UpdateEntityResult::create($headers); break; case BatchOperationType::DELETE_ENTITY_OPERATION: $entries[] = Resources::BATCH_ENTITY_DEL_MSG; break; default: throw new \InvalidArgumentException(); } } catch (ServiceException $e) { $entries[] = BatchError::create($e, $response->headers); } } $result->setEntries($entries); return $result; }
/** * Does actual work for update and merge entity APIs. * * @param string $table The table name. * @param Models\Entity $entity The entity instance to use. * @param string $verb The HTTP method. * @param boolean $useETag The flag to include etag or not. * @param Models\TableServiceOptions $options The optional parameters. * * @return Models\UpdateEntityResult */ private function _putOrMergeEntityImpl($table, $entity, $verb, $useETag, $options) { $context = $this->_constructPutOrMergeEntityContext($table, $entity, $verb, $useETag, $options); $response = $this->sendContext($context); return UpdateEntityResult::create(HttpFormatter::formatHeaders($response->getHeaders())); }