コード例 #1
0
 /**
  * @param string $customerSessionId
  * @param string $customerIpAddress
  * @param string $customerUserAgent
  */
 public function __construct($customerSessionId = 'auto', $customerIpAddress = 'auto', $customerUserAgent = 'auto')
 {
     $this->customerSessionId = (string) $customerSessionId;
     $this->customerIpAddress = (string) $customerIpAddress;
     $this->customerUserAgent = (string) $customerUserAgent;
     if (!$this->customerIpAddress || 'auto' === strtolower($this->customerIpAddress)) {
         $this->customerIpAddress = Utils::getIP();
     }
     if (!$this->customerUserAgent || 'auto' === strtolower($this->customerUserAgent)) {
         $this->customerUserAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
     }
     if (!$this->customerSessionId || 'auto' === strtolower($this->customerSessionId)) {
         $this->customerSessionId = session_id();
         if (!$this->customerSessionId) {
             // hopefully we never have to get here
             $arr = array();
             $arr[] = $this->customerUserAgent;
             $arr[] = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : '';
             $arr[] = isset($_SERVER['HTTP_ACCEPT_ENCODING']) ? $_SERVER['HTTP_ACCEPT_ENCODING'] : '';
             $arr[] = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '';
             $arr[] = $this->customerIpAddress;
             $arr[] = isset($_SERVER['REMOTE_PORT']) ? $_SERVER['REMOTE_PORT'] : '';
             $arr[] = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';
             $arr[] = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '';
             $arr[] = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : '';
             $this->customerSessionId = hash('sha256', implode($arr, '-'));
             // attempt to footprint the specific user (best guess)
         }
     }
 }
コード例 #2
0
 protected function set__amenity($value)
 {
     $this->amenity = trim(Utils::htmlEntitiesDecode($value));
 }
コード例 #3
0
 protected function set__timeZoneDescription($value)
 {
     $this->timeZoneDescription = Utils::htmlEntitiesDecode($value);
 }
コード例 #4
0
 protected function set__amount($value)
 {
     $this->amount = Utils::htmlEntitiesDecode($value);
 }
コード例 #5
0
 protected function set__descriptionLong($value)
 {
     $this->descriptionLong = trim(Utils::htmlEntitiesDecode($value));
 }
コード例 #6
0
 /**
  * Refreshes the XML object (SimpleXMLElement) of the class based on its registered properties. 
  * This syncronizes the underlying XML structure with the class' property structure for use in API requests. 
  */
 public function refreshXML()
 {
     $this->xml = new SimpleXMLElement('<' . static::$ROOT . ' />');
     if (isset(static::$propertyMap) && is_array(static::$propertyMap)) {
         foreach (static::$propertyMap as $property => $type) {
             if (!isset($this->{$property})) {
                 continue;
             }
             if (Utils::isStringValueScalar($type, true)) {
                 if (stripos($type, 'bool') !== false) {
                     $this->xml->{$property} = $this->{$property} ? 'true' : 'false';
                 } else {
                     if (method_exists($this, 'get__' . $property)) {
                         $userFuncResult = call_user_func(array($this, 'get__' . $property));
                         if ($userFuncResult !== null) {
                             $this->xml->{$property} = (string) $userFuncResult;
                         }
                     } else {
                         $this->xml->{$property} = (string) $this->{$property};
                     }
                 }
             } else {
                 if (is_subclass_of($type, 'zamnuts\\EANAPIClient\\Common\\SupportModels\\EANAbstractSupportModel')) {
                     if (method_exists($this->{$property}, 'refreshXML')) {
                         $this->{$property}->refreshXML();
                     }
                     $this->xml->{$property} = $this->{$property}->xml;
                 } else {
                     if ($type === 'DateTime' && $this->{$property} instanceof DateTime) {
                         $this->xml->{$property} = $this->{$property}->format('m/d/Y');
                     }
                 }
             }
         }
     }
 }
コード例 #7
0
 protected function set__resendConfirmationEmail($value)
 {
     $this->resendConfirmationEmail = Utils::anyToBoolean($value);
 }
コード例 #8
0
 protected function set__url($value)
 {
     $this->url = $this->supplementUrlPrefix(trim(Utils::htmlEntitiesDecode($value)));
 }
コード例 #9
0
 protected function set__existingItinerary($value)
 {
     $this->existingItinerary = Utils::anyToBoolean($value);
 }
コード例 #10
0
 protected function set__verboseMessage($value)
 {
     $this->verboseMessage = Utils::htmlEntitiesDecode($value);
 }
コード例 #11
0
 protected function set__checkOutTime($value)
 {
     $this->checkOutTime = trim(Utils::htmlEntitiesDecode($value));
 }
コード例 #12
0
 protected function set__sendReservationEmail($value)
 {
     $this->sendReservationEmail = Utils::anyToBoolean($value);
 }
コード例 #13
0
 /**
  * @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;
 }
コード例 #14
0
 protected function set__includeChildAffiliates($value)
 {
     $this->includeChildAffiliates = Utils::anyToBoolean($value);
 }
コード例 #15
0
 protected function set__description($value)
 {
     $this->description = Utils::htmlEntitiesDecode($value);
     $this->refreshXML();
 }
コード例 #16
0
 protected function set__depositRequired($value)
 {
     $this->depositRequired = Utils::anyToBoolean($value);
 }
コード例 #17
0
 protected function set__locationInDestination($value)
 {
     $this->locationInDestination = Utils::anyToBoolean($value);
 }
コード例 #18
0
 public function refreshXML()
 {
     if (isset($this->adultCount)) {
         $this->xml->numberOfAdults = (string) $this->adultCount;
     }
     if (isset($this->childrenAges) && is_array($this->childrenAges)) {
         $numChildrenAges = count($this->childrenAges);
         $this->xml->numberOfChildren = (string) $numChildrenAges;
         if ($numChildrenAges) {
             $list = implode(',', $this->childrenAges);
             $this->xml->childAges = $list;
         }
     }
     foreach (self::$partialPropertyMap as $property => $type) {
         if (isset($this->{$property}) && Utils::isStringValueScalar($type, false)) {
             $this->xml->{$property} = (string) $this->{$property};
         }
     }
 }
コード例 #19
0
 protected function set__propertyRestricted($value)
 {
     $this->propertyRestricted = Utils::anyToBoolean($value);
 }
コード例 #20
0
 /**
  * @return void
  */
 protected function normalizeLocale()
 {
     // determine auto or user-defined locale
     if ($this->locale) {
         if ('auto' === strtolower($this->locale)) {
             $this->cachedLocale = Utils::clientLocale(self::DEFAULT_LOCALE);
         } else {
             $this->cachedLocale = $this->locale;
         }
     }
     // determine auto or user-defined currency
     if ($this->currency) {
         if ('auto' === strtolower($this->currency)) {
             if ($this->cachedLocale) {
                 $iso31661 = strtoupper((string) Locale::getRegion($this->cachedLocale));
                 if ($iso31661 && isset(self::$TABLE_LOCALE_CURRENCY[$iso31661])) {
                     $this->cachedCurrency = self::$TABLE_LOCALE_CURRENCY[$iso31661];
                 } else {
                     $this->cachedCurrency = self::DEFAULT_CURRENCY;
                 }
             } else {
                 $this->cachedCurrency = self::DEFAULT_CURRENCY;
             }
         } else {
             $this->cachedCurrency = $this->currency;
         }
     }
     // normalize
     $this->cachedLocale = (string) $this->cachedLocale;
     $this->cachedLocale = Locale::canonicalize($this->cachedLocale ? $this->cachedLocale : self::DEFAULT_LOCALE);
     $this->cachedCurrency = strtoupper((string) $this->cachedCurrency);
     // validate locale
     $iso31661 = strtoupper((string) Locale::getRegion($this->cachedLocale));
     if (!$iso31661 || !isset(self::$LOCALES[$iso31661])) {
         $this->cachedLocale = self::DEFAULT_LOCALE;
         $iso31661 = strtoupper((string) Locale::getRegion($this->cachedLocale));
     }
     // validate currency
     if (!isset(self::$CURRENCIES[$this->cachedCurrency])) {
         if ($iso31661 && isset(self::$TABLE_LOCALE_CURRENCY[$iso31661])) {
             $this->cachedCurrency = self::$TABLE_LOCALE_CURRENCY[$iso31661];
         } else {
             $this->cachedCurrency = self::DEFAULT_CURRENCY;
         }
     }
     // cache currency symbol
     $iso31661 = self::$TABLE_CURRENCY_LOCALE[self::DEFAULT_CURRENCY];
     if ($this->cachedCurrency && isset(self::$TABLE_CURRENCY_LOCALE[$this->cachedCurrency])) {
         $iso31661 = self::$TABLE_CURRENCY_LOCALE[$this->cachedCurrency];
     }
     $locale = self::DEFAULT_LOCALE;
     if (isset(self::$LOCALES[$iso31661])) {
         $locale = self::$LOCALES[$iso31661];
     }
     $formatter = new NumberFormatter($locale, NumberFormatter::CURRENCY);
     $this->cachedSymbol = (string) $formatter->getSymbol(NumberFormatter::CURRENCY_SYMBOL);
 }
コード例 #21
0
 protected function set__deepLink($value)
 {
     $this->deepLink = Utils::htmlEntitiesDecode((string) $value);
 }