Converts an object to an XML string. The root element name is passed in as
a parameter, and each field of the object becomes a child element. Array
values are represented by multiples instances of that element. Methods on
the object are ignored.
public ConvertObjectToXml ( mixed $object, string $rootElementName, boolean $useXsiType ) : string | ||
$object | mixed | the object to serialize |
$rootElementName | string | the name of the root element |
$useXsiType | boolean | whether the xsi:type will be added into XML tags when available |
리턴 | string | the XML serialized string of the object |
/** * Generates the parameters to use for the download request. * @param mixed $reportDefinition the report definition, as an ID or object * @return array the parameters */ private static function GetParams($reportDefinition) { $params = array(); if (is_numeric($reportDefinition)) { $params['__rd'] = $reportDefinition; } else { if (is_object($reportDefinition) || is_array($reportDefinition)) { $serializer = new XmlSerializer(); $params['__rdxml'] = $serializer->ConvertObjectToXml($reportDefinition, 'reportDefinition', false); } else { throw new ReportDownloadException('Invalid report definition type: ' . $reportDefinition); } } return $params; }
/** * Creates the HTTP headers and body for incremental upload request that will * be used to upload batch operations to. Content-Length and Content-Range * are required for incremental upload. * * @param array $operations operations to be uploaded to the upload URL * @param bool $isLastRequest if this is last upload request * @return array an associative array containing the HTTP headers, body, and * content length of incremental upload request */ private function PrepareIncrementalUploadRequest(array $operations, $isLastRequest) { $headers = array('Content-Type' => self::$UPLOAD_URL_HEADER_CONTENT_TYPE); $batchJobOpsMutate = new BatchJobOpsMutate(); $batchJobOpsMutate->operations = $operations; // Get body of this HTTP upload request. $serializer = new XmlSerializer(); $content = $this->PostProcessContent($serializer->ConvertObjectToXml($batchJobOpsMutate, 'ns1:mutate', true), $this->totalContentBytes == 0, $isLastRequest); $contentLength = mb_strlen($content, '8bit'); $headers['Content-Length'] = $contentLength; // On the last request, specify the total number of bytes. // e.g., bytes 500-999/1000 $lowerBound = $this->totalContentBytes; $upperBound = $this->totalContentBytes + $contentLength - 1; $totalBytes = $isLastRequest ? strval($upperBound + 1) : '*'; $contentRange = sprintf('bytes %d-%d/%s', $lowerBound, $upperBound, $totalBytes); $headers['Content-Range'] = $contentRange; return array('headers' => $headers, 'body' => $content, 'length' => $contentLength); }
/** * @covers XmlSerializer::ConvertObjectToXml * @covers XmlSerializer::ConvertObjectToElement * @covers XmlSerializer::ConvertObjectToNodeValue */ public function testConvertObjectToXmlMutateRequest() { $serializer = new XmlSerializer(); $result = $serializer->ConvertObjectToXml(XmlTestHelper::$MUTATE_REQUEST_OBJECT, 'ns1:mutate', true); $this->assertEquals(XmlTestHelper::$NAMESPACED_MUTATE_REQUEST_XML, $result); }
/** * Creates the headers and body of HTTP upload request that will be used to * upload batch operations to. * * @param array $operations operations to be uploaded to the upload URL * @return array an associative array containing the headers and body of HTTP * upload request */ private function PrepareUploadRequest(array $operations) { $headers = array('Content-Type' => self::$UPLOAD_URL_HEADER_CONTENT_TYPE); $batchJobOpsMutate = new BatchJobOpsMutate(); $batchJobOpsMutate->operations = $operations; // Get body of this HTTP upload request. $serializer = new XmlSerializer(); $xml = $serializer->ConvertObjectToXml($batchJobOpsMutate, 'ns1:mutate', true); return array('headers' => $headers, 'body' => $xml); }