create_cors_config ( $bucket, $opt )

Create a new CORS configuration.

Access

public

Parameters

Parameter

Type

Required

Description

$bucket

string

Required

The name of the bucket to use.

$opt

array

Optional

An associative array of parameters that can have the following keys:

  • cors_rule - array - Required - One or more rule-sets.
    • x - array - Required - This represents a simple array index.
      • allowed_header - array - Required - Used in response to a preflight request to indicate which HTTP headers can be used when making the actual request.
      • allowed_method - array - Required - An array of HTTP methods to allow. There must be at least one method set. [Allowed values: `GET`, `PUT`, `HEAD`, `POST`, `DELETE`]
      • allowed_origin - array - Required - An array of hostnames to allow. This could be `*` to indicate it is open to all domains. If one of them contains the string `*`, then there can be exactly one.
      • expose_header - string - Optional - Enable the browser to read this header.
      • id - string - Optional - Unique identifier for the rule. The value cannot be longer than 255 characters.
      • max_age - integer - Optional - Alter the client’s caching behavior for the pre-flight request.
  • curlopts - array - Optional - A set of values to pass directly into curl_setopt(), where the key is a pre-defined CURLOPT_* constant.
  • returnCurlHandle - boolean - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.

Returns

Type

Description

CFResponse

A CFResponse object containing a parsed HTTP response.

Examples


							

Source

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

public function create_cors_config($bucket, $opt = null)
{
    if (!$opt) $opt = array();
    $opt['verb'] = 'PUT';
    $opt['sub_resource'] = 'cors';
    $opt['headers'] = array(
        'Content-Type' => 'application/xml'
    );

    $xml = simplexml_load_string($this->cors_config_xml, $this->parser_class);

    if (isset($opt['cors_rule']) && is_array($opt['cors_rule']))
    {
        foreach ($opt['cors_rule'] as $rule_set)
        {
            // New rule node
            $xrule = $xml->addChild('CORSRule');

            // ID node
            if (isset($rule_set['id']))
            {
                $xrule->addChild('ID', $rule_set['id']);
            }

            // ExposeHeader node
            if (isset($rule_set['expose_header']))
            {
                $xrule->addChild('ExposeHeader', $rule_set['expose_header']);
            }

            // MaxAgeSeconds node
            if (isset($rule_set['max_age']))
            {
                $xrule->addChild('MaxAgeSeconds', $rule_set['max_age']);
            }

            // AllowedHeader node
            if (isset($rule_set['allowed_header']))
            {
                if (!is_array($rule_set['allowed_header']))
                {
                    $rule_set['allowed_header'] = array($rule_set['allowed_header']);
                }

                foreach ($rule_set['allowed_header'] as $method)
                {
                    $xrule->addChild('AllowedHeader', $method);
                }
            }

            // AllowedMethod node
            if (isset($rule_set['allowed_method']))
            {
                if (!is_array($rule_set['allowed_method']))
                {
                    $rule_set['allowed_method'] = array($rule_set['allowed_method']);
                }

                foreach ($rule_set['allowed_method'] as $method)
                {
                    $xrule->addChild('AllowedMethod', $method);
                }
            }

            // AllowedOrigin node
            if (isset($rule_set['allowed_origin']))
            {
                if (!is_array($rule_set['allowed_origin']))
                {
                    $rule_set['allowed_origin'] = array($rule_set['allowed_origin']);
                }

                foreach ($rule_set['allowed_origin'] as $method)
                {
                    $xrule->addChild('AllowedOrigin', $method);
                }
            }
        }
    }

    $opt['body'] = $xml->asXML();

    // Authenticate to S3
    return $this->authenticate($bucket, $opt);
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback