/** * @param string $property * @param PPXmlMessage|string $value * @param string $namespace * @return string */ private function buildProperty($property, $value, $namespace = 'ebl') { $annotations = PPUtils::propertyAnnotations($this, $property); if (!empty($annotations['namespace'])) { $namespace = $annotations['namespace']; } if (!empty($annotations['name'])) { $property = $annotations['name']; } if ($namespace === true) { $el = '<' . $property; } else { $el = '<' . $namespace . ':' . $property; } if (!is_object($value)) { $el .= '>' . PPUtils::escapeInvalidXmlCharsRegex($value); } else { if (substr($value = $value->toXMLString(), 0, 1) === '<' || $value == '') { $el .= '>' . $value; } else { $el .= ' ' . $value; } } if ($namespace === true) { return $el . '</' . $property . '>'; } else { return $el . '</' . $namespace . ':' . $property . '>'; } }
/** * @param string $prefix * @return string */ public function toNVPString($prefix = '') { $nvp = array(); foreach (get_object_vars($this) as $property => $defaultValue) { if (($propertyValue = $this->{$property}) === NULL || $propertyValue == NULL) { continue; } if (is_object($propertyValue)) { $nvp[] = $propertyValue->toNVPString($prefix . $property . '.'); // prefix } elseif (is_array($defaultValue) || is_array($propertyValue)) { foreach (array_values($propertyValue) as $i => $item) { if (!is_object($item)) { $nvp[] = $prefix . $property . "({$i})" . '=' . urlencode($item); } else { $nvp[] = $item->toNVPString($prefix . $property . "({$i})."); } } } else { // Handle classes with attributes if ($property == 'value' && ($anno = PPUtils::propertyAnnotations($this, $property)) != NULL && isset($anno['value'])) { $nvpKey = substr($prefix, 0, -1); // Remove the ending '.' } else { $nvpKey = $prefix . $property; } $nvp[] = $nvpKey . '=' . urlencode($propertyValue); } } return implode('&', $nvp); }