public function refreshXML()
 {
     $this->xml = new SimpleXMLElement('<' . static::$ROOT . ' />');
     if (isset(static::$attributeMap) && is_array(static::$attributeMap)) {
         foreach (static::$attributeMap as $attribute => $type) {
             $this->xml->addAttribute($attribute, (string) $this->{$attribute});
         }
     }
     foreach ($this->items as $item) {
         /* @var $item EANAbstractSupportModel */
         if (method_exists($item, 'refreshXML')) {
             $item->refreshXML();
         }
         XMLUtils::appendSXE($this->xml, $item->xml);
     }
 }
Exemplo n.º 2
0
 /**
  * As if one were to perform tidyPartialHTML and nodeListToString in series.
  * @param string $dirtyHtml The really nasty dirty HTML that should be washed with soap.
  * @param bool $isSpecialCharEncoded Set to true if the incoming is encoded with htmlspecialchars or htmlentities (or Utils::htmlEntitiesEncode).
  * @param bool $autoDetectEncoded Defaults to true, will auto-detect encoded entities/html. Takes precedence over $isSpecialCharEncoded.
  * @return string An empty string on failure, or something clean if successful.
  */
 public static function tidyPartialHTMLToString($dirtyHtml, $isSpecialCharEncoded = false, $autoDetectEncoded = true)
 {
     if (!isset($autoDetectEncoded)) {
         $autoDetectEncoded = false;
     }
     $dirtyHtml = (string) $dirtyHtml;
     if ($autoDetectEncoded) {
         $hasTags = static::hasTags($dirtyHtml);
         $hasEntities = static::hasEntities($dirtyHtml);
         if ($hasEntities && !$hasTags) {
             $dirtyHtml = Utils::htmlEntitiesDecode($dirtyHtml);
         }
     } else {
         if ($isSpecialCharEncoded) {
             $dirtyHtml = Utils::htmlEntitiesDecode($dirtyHtml);
         }
     }
     $cleanHtml = '';
     $nodes = XMLUtils::tidyPartialHTML($dirtyHtml);
     if (isset($nodes)) {
         $cleanHtml = XMLUtils::nodeListToString($nodes);
     }
     return $cleanHtml;
 }
Exemplo n.º 3
0
 protected function prepareRequest()
 {
     // if we're working with a cached result, we can only send specific fields
     $cacheKey = $this->get__cacheKey();
     $cacheLocation = $this->get__cacheLocation();
     $supplierType = $this->get__supplierType();
     if (isset($cacheKey, $cacheLocation)) {
         $this->xmlRequest->cacheKey = $cacheKey;
         $this->xmlRequest->cacheLocation = $cacheLocation;
         if (isset($supplierType)) {
             $this->xmlRequest->supplierType = $supplierType;
         }
         return;
     }
     // not working with a cached result, so just prepare the request per usual
     if (isset($this->searchMethod)) {
         $searchMethodProperties = $this->searchMethod->renderPreparedArray();
         foreach ($searchMethodProperties as $tag => $value) {
             $this->xmlRequest->addChild($tag, (string) $value);
         }
     }
     foreach (self::$propertyMap as $property => $type) {
         if (!isset($this->{$property})) {
             continue;
         }
         switch ($type) {
             case 'DateTime':
                 $this->xmlRequest->{$property} = $this->{$property}->format('m/d/Y');
                 break;
             case 'EANRoomGroup':
                 XMLUtils::appendSXE($this->xmlRequest, $this->{$property}->xml);
                 break;
             case 'int':
             case 'float':
             case 'string':
                 if (method_exists($this, 'get__' . $property)) {
                     $this->xmlRequest->{$property} = $this->{'get__' . $property}();
                 } else {
                     $this->xmlRequest->{$property} = (string) $this->{$property};
                 }
                 break;
             case 'boolean':
                 $this->xmlRequest->{$property} = $this->{$property} ? 'true' : 'false';
                 break;
         }
     }
 }
Exemplo n.º 4
0
 protected function set__cancellationPolicy($value)
 {
     $this->cancellationPolicy = XMLUtils::tidyPartialHTMLToString($value, true);
 }
 protected function set__checkInInstructions($value)
 {
     $this->checkInInstructions = XMLUtils::tidyPartialHTMLToString($value, true);
 }
 protected function set__renovationsDescription($value)
 {
     $this->renovationsDescription = XMLUtils::tidyPartialHTMLToString($value);
 }
 protected function prepareRequest()
 {
     foreach (self::$propertyMap as $property => $type) {
         if (!isset($this->{$property})) {
             continue;
         }
         switch ($type) {
             case 'DateTime':
                 $this->xmlRequest->{$property} = $this->{$property}->format('m/d/Y');
                 break;
             case 'EANReservationAddress':
             case 'EANReservationInfo':
             case 'EANRoomGroup':
                 $this->{$property}->refreshXML();
                 XMLUtils::appendSXE($this->xmlRequest, $this->{$property}->xml);
                 break;
             case 'int':
             case 'float':
             case 'string':
                 if (method_exists($this, 'get__' . $property)) {
                     $this->xmlRequest->{$property} = $this->{'get__' . $property}();
                 } else {
                     $this->xmlRequest->{$property} = (string) $this->{$property};
                 }
                 break;
             case 'boolean':
                 $this->xmlRequest->{$property} = $this->{$property} ? 'true' : 'false';
                 break;
         }
     }
 }
 /**
  * @return boolean
  */
 public function execute()
 {
     $this->curl = new Curl();
     $this->curl->setOpt(CURLOPT_ENCODING, 'gzip');
     $this->curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
     $this->curl->setOpt(CURLOPT_HTTPHEADER, array('Accept: application/xml'));
     $this->prepareRequest();
     if (!$this->xmlRequest) {
         $this->lastError = new Exception('Request XML is not defined.');
         return false;
     }
     if (!isset(static::$API_METHOD) || !static::$API_METHOD) {
         $this->lastError = new Exception('API method is not defined.');
         return false;
     }
     $url = rtrim(static::ENDPOINT, '/') . '/' . static::ENDPOINT_VERSION . '/' . static::$API_METHOD;
     $data = array();
     if (static::$HTTP_METHOD === EANFacade::HTTP_METHOD_POST) {
         $data['xml'] = XMLUtils::SXEasXML($this->xmlRequest);
         $url .= '?' . Utils::httpBuildQuery3986($this->params);
     } else {
         $data = array_merge($this->params, array('xml' => XMLUtils::SXEasXML($this->xmlRequest)));
     }
     if (static::$HTTP_METHOD === EANFacade::HTTP_METHOD_GET) {
         $this->curl->get($url, $data);
         $this->curl->close();
     } else {
         if (static::$HTTP_METHOD === EANFacade::HTTP_METHOD_POST) {
             $this->curl->post($url, $data);
             $this->curl->close();
         } else {
             $this->lastError = new Exception('Invalid method for API call.');
             return false;
         }
     }
     if ($this->curl->error) {
         $this->lastError = new Exception($this->curl->errorMessage);
         return false;
     }
     try {
         if ($this->curl->response instanceof SimpleXMLElement) {
             $this->xmlResponse = $this->curl->response;
         } else {
             $this->xmlResponse = new SimpleXMLElement($this->curl->response);
         }
     } catch (Exception $e) {
         $this->lastError = $e;
         return false;
     }
     $this->lastError = null;
     $this->prepareResponse();
     return true;
 }
 /**
  * @return string
  */
 public function asXML()
 {
     return XMLUtils::SXEasXML($this->xml);
 }
 protected function set__shortDescription($value)
 {
     $this->shortDescription = XMLUtils::tidyPartialHTMLToString($value, true);
 }
Exemplo n.º 11
0
 protected function set__otherInformation($value)
 {
     $this->otherInformation = XMLUtils::tidyPartialHTMLToString($value);
 }