Exemplo n.º 1
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};
         }
     }
 }
 /**
  * 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');
                     }
                 }
             }
         }
     }
 }