/**
  * Marshall a POPO object to be XML
  *
  * @param IPPIntuitEntity $entity The POPO object
  * @param string $urlResource the type of the POPO object
  * @return string the XML of the POPO object 
  */
 public static function getPostXmlFromArbitraryEntity($entity, &$urlResource)
 {
     if (NULL == $entity) {
         return FALSE;
     }
     $xmlElementName = XmlObjectSerializer::cleanPhpClassNameToIntuitEntityName(get_class($entity));
     $urlResource = strtolower($xmlElementName);
     $httpsPostBody = XmlObjectSerializer::getXmlFromObj($entity);
     return $httpsPostBody;
 }
Ejemplo n.º 2
0
 /**
  * This method executes the batch request.
  */
 public function Execute()
 {
     $this->serviceContext->IppConfiguration->Logger->CustomLogger->Log(TraceLevel::Info, "Started Executing Method Execute for Batch");
     // Create Intuit Batch Request
     $intuitBatchRequest = new IPPIntuitBatchRequest();
     $intuitBatchRequest->BatchItemRequest = $this->batchRequests;
     $uri = "company/{1}/batch?requestid=" . rand() . rand();
     $uri = str_replace('{1}', $this->serviceContext->realmId, $uri);
     // Creates request parameters
     $requestParameters = NULL;
     if (0) {
         // No JSON support here yet
         //$requestParameters = new RequestParameters($uri, 'POST', CoreConstants::CONTENTTYPE_APPLICATIONJSON, NULL);
     } else {
         $requestParameters = new RequestParameters($uri, 'POST', CoreConstants::CONTENTTYPE_APPLICATIONXML, NULL);
     }
     $restRequestHandler = new SyncRestHandler($this->serviceContext);
     try {
         // Get literal XML representation of IntuitBatchRequest into a DOMDocument
         $httpsPostBodyPreProcessed = XmlObjectSerializer::getPostXmlFromArbitraryEntity($intuitBatchRequest, $urlResource);
         $doc = new DOMDocument();
         $domObj = $doc->loadXML($httpsPostBodyPreProcessed);
         $xpath = new DOMXpath($doc);
         // Replace generically-named IntuitObject nodes with tags that describe contained objects
         $objectIndex = 0;
         while (1) {
             $matchingElementArray = $xpath->query("//IntuitObject");
             if (is_null($matchingElementArray)) {
                 break;
             }
             if ($objectIndex >= count($intuitBatchRequest->BatchItemRequest)) {
                 break;
             }
             foreach ($matchingElementArray as $oneNode) {
                 // Found a DOMNode currently named "IntuitObject".  Need to rename to
                 // entity that describes it's contents, like "ns0:Customer" (determine correct
                 // name by inspecting IntuitObject's class).
                 if ($intuitBatchRequest->BatchItemRequest[$objectIndex]->IntuitObject) {
                     // Determine entity name to use
                     $entityClassName = get_class($intuitBatchRequest->BatchItemRequest[$objectIndex]->IntuitObject);
                     $entityTransferName = XmlObjectSerializer::cleanPhpClassNameToIntuitEntityName($entityClassName);
                     $entityTransferName = 'ns0:' . $entityTransferName;
                     // Replace old-named DOMNode with new-named DOMNode
                     $newNode = $oneNode->ownerDocument->createElement($entityTransferName);
                     if ($oneNode->attributes->length) {
                         foreach ($oneNode->attributes as $attribute) {
                             $newNode->setAttribute($attribute->nodeName, $attribute->nodeValue);
                         }
                     }
                     while ($oneNode->firstChild) {
                         $newNode->appendChild($oneNode->firstChild);
                     }
                     $oneNode->parentNode->replaceChild($newNode, $oneNode);
                 }
                 break;
             }
             $objectIndex++;
         }
         $httpsPostBody = $doc->saveXML();
         list($responseCode, $responseBody, $responseError) = $restRequestHandler->GetResponse($requestParameters, $httpsPostBody, NULL);
     } catch (Exception $e) {
         IdsExceptionManager::HandleException($e);
     }
     CoreHelper::CheckResponseErrorAndThrowException($this->serviceContext, $responseError);
     CoreHelper::CheckNullResponseAndThrowException($responseBody);
     try {
         $this->batchResponses = array();
         $this->intuitBatchItemResponses = array();
         // No JSON support here yet
         // de serialize object
         $responseXmlObj = simplexml_load_string($responseBody);
         foreach ($responseXmlObj as $oneXmlObj) {
             // process batch item
             $intuitBatchResponse = $this->ProcessBatchItemResponse($oneXmlObj);
             $this->intuitBatchItemResponses[] = $intuitBatchResponse;
             if ($intuitBatchResponse && $intuitBatchResponse->entities && count($intuitBatchResponse->entities)) {
                 $this->batchResponses[] = $intuitBatchResponse->entities;
             }
         }
     } catch (Exception $e) {
         return NULL;
     }
     $this->serviceContext->IppConfiguration->Logger->CustomLogger->Log(TraceLevel::Info, "Finished Execute method for batch.");
 }