PayPal\Core\PPMessage::toNVPString PHP Method

toNVPString() public method

public toNVPString ( string $prefix = '' ) : string
$prefix string
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);
    }