if_bucket_policy_exists ( $bucket )

Gets whether or not the specified Amazon S3 bucket has a bucket policy associated with it.

Access

public

Parameters

Parameter

Type

Required

Description

$bucket

string

Required

The name of the bucket to use.

Returns

Type

Description

boolean

A value of true if a bucket policy exists, or a value of false if one does not.

Examples

Check if a bucket policy exists.

// Instantiate the class
$s3 = new AmazonS3();
$bucket = 'my-bucket' . strtolower($s3->key);

$response = $s3->if_bucket_policy_exists($bucket);

// Success? (Boolean, not a CFResponse object)
var_dump($response);
Result:
bool(true)

Related Methods

Source

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

public function if_bucket_policy_exists($bucket)
{
    if ($this->use_batch_flow)
    {
        // @codeCoverageIgnoreStart
        throw new S3_Exception(__FUNCTION__ . '() cannot be batch requested');
        // @codeCoverageIgnoreEnd
    }

    $response = $this->get_bucket_policy($bucket);

    if ($response->isOK()) { return true; }
    elseif ($response->status === 404) { return false; }

    // @codeCoverageIgnoreStart
    return null;
    // @codeCoverageIgnoreEnd
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback