Scalr\Service\Aws\S3\V20060301\S3Api::getBucketAcl PHP Method

getBucketAcl() public method

This implementation of the GET operation uses the acl subresource to return the access control list (ACL) of a bucket. To use GET to return the ACL of the bucket, you must have READ_ACP access to the bucket. If READ_ACP permission is granted to the anonymous user, you can return the ACL of the bucket without using an authorization header.
public getBucketAcl ( string $bucketName ) : Scalr\Service\Aws\S3\DataType\AccessControlPolicyData
$bucketName string A bucket name
return Scalr\Service\Aws\S3\DataType\AccessControlPolicyData Returns object which describes ACL for the bucket.
    public function getBucketAcl($bucketName)
    {
        $result = null;
        $options = array('_subdomain' => (string) $bucketName);
        $response = $this->client->call('GET', $options, '/?acl');
        if ($response->getError() === false) {
            $sxml = simplexml_load_string($response->getRawContent());
            if (!isset($sxml->Owner)) {
                throw new S3Exception('Unexpected response! ' . $response->getRawContent());
            }
            $list = new AccessControlGrantList();
            $result = new AccessControlPolicyData();
            $result->setS3($this->s3);
            $result->setOriginalXml($response->getRawContent());
            $result->setBucketName((string) $bucketName);
            $result->setOwner(new OwnerData((string) $sxml->Owner->ID, (string) $sxml->Owner->DisplayName));
            $result->setAccessControlList($list);
            if (!empty($sxml->AccessControlList->Grant)) {
                /* @var $sgrant \SimpleXMLElement */
                foreach ($sxml->AccessControlList->Grant as $sgrant) {
                    $attr = $sgrant->Grantee->attributes('xsi', true);
                    $grantee = new GranteeData();
                    $grantee->type = (string) $attr->type;
                    if (isset($sgrant->Grantee->URI)) {
                        $grantee->uri = (string) $sgrant->Grantee->URI;
                    } else {
                        $grantee->granteeId = (string) $sgrant->Grantee->ID;
                        $grantee->displayName = (string) $sgrant->Grantee->DisplayName;
                    }
                    $grant = new AccessControlGrantData();
                    $grant->setPermission(new PermissionData((string) $sgrant->Permission));
                    $grant->setGrantee($grantee);
                    $list->append($grant);
                    unset($grant);
                    unset($grantee);
                }
            }
        }
        return $result;
    }