6 abstract class PPXmlMessage
12 public function toSOAP()
14 return $this->toXMLString();
22 public function toXMLString()
24 if (count($properties = get_object_vars($this)) >= 2 && array_key_exists('value', $properties)) {
25 $attributes = array();
26 foreach (array_keys($properties) as $property) {
27 if ($property === 'value') continue;
28 if (($annots = PPUtils::propertyAnnotations($this, $property)) && isset($annots['attribute'])) {
29 if (($propertyValue = $this->{$property}) === NULL || $propertyValue == NULL) {
34 $attributes[] = $property . '="' . PPUtils::escapeInvalidXmlCharsRegex($propertyValue) . '"';
38 if (count($attributes)) {
39 return implode(' ', $attributes) . '>' . PPUtils::escapeInvalidXmlCharsRegex($this->value);
44 foreach ($properties as $property => $defaultValue) {
45 if (($propertyValue = $this->{$property}) === NULL || $propertyValue == NULL) {
49 if (is_array($defaultValue) || is_array($propertyValue)) {
50 foreach ($propertyValue as $item) {
51 if (!is_object($item)) {
52 $xml[] = $this->buildProperty($property, $item);
54 $xml[] = $this->buildProperty($property, $item);
59 $xml[] = $this->buildProperty($property, $propertyValue);
69 * @param string $property
70 * @param PPXmlMessage|string $value
71 * @param string $namespace
74 private function buildProperty($property, $value, $namespace = 'ebl')
76 $annotations = PPUtils::propertyAnnotations($this, $property);
77 if (!empty($annotations['namespace'])) {
78 $namespace = $annotations['namespace'];
80 if (!empty($annotations['name'])) {
81 $property = $annotations['name'];
84 $el = '<' . $namespace . ':' . $property;
85 if (!is_object($value)) {
86 $el .= '>' . PPUtils::escapeInvalidXmlCharsRegex($value);
89 if (substr($value = $value->toXMLString(), 0, 1) === '<' || $value=='') {
97 return $el . '</' . $namespace . ':' . $property . '>';
104 * @param string $prefix
106 public function init(array $map = array(), $prefix = '')
112 if (($first = reset($map)) && !is_array($first) && !is_numeric(key($map))) {
113 parent::init($map, $prefix);
117 $propertiesMap = PPUtils::objectProperties($this);
119 foreach ($map as $element) {
121 if (empty($element) || empty($element['name'])) {
124 } elseif (!array_key_exists($property = strtolower($element['name']), $propertiesMap)) {
125 if (!preg_match('~^(.+)[\[\(](\d+)[\]\)]$~', $property, $m)) {
129 $element['name'] = $m[1];
130 $element['num'] = $m[2];
132 $element['name'] = $propertiesMap[strtolower($element['name'])];
133 if(PPUtils::isPropertyArray($this, $element['name'])) {
134 $arrayCtr[$element['name']] = isset($arrayCtr[$element['name']]) ? ($arrayCtr[$element['name']]+1) : 0;
135 $element['num'] = $arrayCtr[$element['name']];
137 if (!empty($element["attributes"]) && is_array($element["attributes"])) {
138 foreach ($element["attributes"] as $key => $val) {
139 $element["children"][] = array(
145 if (isset($element['text'])) {
146 $element["children"][] = array(
148 'text' => $element['text'],
152 $this->fillRelation($element['name'], $element);
154 } elseif (!empty($element['text'])) {
155 $this->{$element['name']} = $element['text'];
157 } elseif (!empty($element["children"]) && is_array($element["children"])) {
158 $this->fillRelation($element['name'], $element);
166 * @param string $property
167 * @param array $element
169 private function fillRelation($property, array $element)
171 if (!class_exists($type = PPUtils::propertyType($this, $property))) {
172 trigger_error("Class $type not found.", E_USER_NOTICE);
173 return; // just ignore
176 if (isset($element['num'])) { // array of objects
177 $this->{$property}[$element['num']] = $item = new $type();
178 $item->init($element['children']);
181 $this->{$property} = new $type();
182 $this->{$property}->init($element["children"]);