remove_cname ( $xml, $cname )

Removes one or more CNAMEs from a DistibutionConfig XML document.

Access

public

Parameters

Parameter

Type

Required

Description

$xml

CFSimpleXML
CFResponse
string

Required

The source DistributionConfig XML to make updates to. Can be the CFSimpleXML body of a get_distribution_config() response, the entire CFResponse of a get_distribution_config() response, or a string of XML generated by generate_config_xml() or update_config_xml().

$cname

string
array

Required

The value or values to remove from the existing list of CNAME values. To add a CNAME value, see update_config_xml().

Returns

Type

Description

string

XML document.

Examples

Remove a CNAME from a distribution.

$cdn = new AmazonCloudFront();

// Sample XML content
$config_xml = $cdn->get_distribution_config('E2L6A3OZHQT5W4');

// Update the XML content
$response = $cdn->remove_cname($config_xml, 'cname.example.com');

// Success?
var_dump($response);

Related Methods

Source

Method defined in services/cloudfront.class.php | Toggle source view (49 lines) | View on GitHub

public function remove_cname($xml, $cname)
{
    // If we receive a full CFResponse object, only use the body.
    if ($xml instanceof CFResponse)
    {
        $xml = $xml->body;
    }

    // If we received a string of XML, convert it into a CFSimpleXML object.
    if (is_string($xml))
    {
        $xml = simplexml_load_string($xml);
    }

    // Let's make sure that we have CNAMEs to remove in the first place.
    if (isset($xml->CNAME))
    {
        // If we have an array of CNAME values...
        if (is_array($cname))
        {
            foreach ($cname as $cn)
            {
                for ($i = 0, $length = sizeof($xml->CNAME); $i < $length; $i++)
                {
                    if ((string) $xml->CNAME[$i] == $cn)
                    {
                        unset($xml->CNAME[$i]);
                        break;
                    }
                }
            }
        }

        // If we only have one CNAME value...
        else
        {
            for ($i = 0, $length = sizeof($xml->CNAME); $i < $length; $i++)
            {
                if ((string) $xml->CNAME[$i] == $cname)
                {
                    unset($xml->CNAME[$i]);
                    break;
                }
            }
        }
    }

    return $xml->asXML();
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback