/** * (non-PHPdoc) * @see \zamnuts\EANAPIClient\Common\SupportModels\EANAbstractSupportModel::loadXML() * @param SimpleXMLElement $xml */ public function loadXML(SimpleXMLElement $xml) { $this->childrenAges = array(); if (isset($xml->numberOfAdults)) { $this->set__adultCount((int) $xml->numberOfAdults); } if (isset($xml->childAges)) { $children = explode(',', $xml->childAges); foreach ($children as $child) { $this->addChild($child); } } if (isset($xml->numberOfChildren)) { $diff = intval($xml->numberOfChildren, 10) - count($this->childrenAges); for ($i = 0; $i < $diff; $i++) { $this->addChild(0); } } foreach (self::$partialPropertyMap as $property => $type) { $this->{$property} = null; if (isset($xml->{$property}) && Utils::isStringValueScalar($type, false)) { $this->{$property} = Utils::castScalar($type, $xml->{$property}); } } $this->refreshXML(); }
/** * For use internally by loadXML. * @param string $type * @param string $property * @param mixed $value * @return boolean */ protected function setInstanceProperty($type, $property, $value) { if (method_exists($this, 'set__' . $property)) { call_user_func(array($this, 'set__' . $property), $value); return true; } else { if (property_exists($this, $property)) { if (Utils::isStringValueScalar($type, true)) { $this->{$property} = Utils::castScalar($type, $value); return true; } else { if (class_exists($type) && is_subclass_of($type, 'zamnuts\\EANAPIClient\\Common\\SupportModels\\IEANSupportModel')) { $this->{$property} = new $type(); $this->{$property}->loadXML($value); return true; } } } } return false; }