PayPal\Core\PPXmlMessage::toXMLString PHP Method

toXMLString() public method

public toXMLString ( ) : string
return string
    public function toXMLString()
    {
        $attributes = array();
        $properties = get_object_vars($this);
        foreach (array_keys($properties) as $property) {
            if (($annots = PPUtils::propertyAnnotations($this, $property)) && isset($annots['attribute'])) {
                if (($propertyValue = $this->{$property}) === null || $propertyValue == null) {
                    $attributes[] = null;
                    continue;
                }
                $attributes[] = $property . '="' . PPUtils::escapeInvalidXmlCharsRegex($propertyValue) . '"';
            }
        }
        $attrs = implode(' ', $attributes) . (count($attributes) > 0 ? ">" : "");
        $xml = array();
        foreach ($properties as $property => $defaultValue) {
            if (($propertyValue = $this->{$property}) === null || $propertyValue == null) {
                continue;
            }
            if (($annots = PPUtils::propertyAnnotations($this, $property)) && isset($annots['attribute'])) {
                continue;
            }
            if (isset($annots['value'])) {
                $xml[] = PPUtils::escapeInvalidXmlCharsRegex($propertyValue);
                break;
            }
            if (is_array($defaultValue) || is_array($propertyValue)) {
                foreach ($propertyValue as $item) {
                    if (!is_object($item)) {
                        $xml[] = $this->buildProperty($property, $item);
                    } else {
                        $xml[] = $this->buildProperty($property, $item);
                    }
                }
            } else {
                $xml[] = $this->buildProperty($property, $propertyValue);
            }
        }
        return $attrs . implode($xml);
    }