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

getObjectAcl() public method

This implementation of the GET operation uses the acl subresource to return the access control list (ACL) of an object. To use this operation, you must have READ_ACP access to the object.
public getObjectAcl ( string $bucketName, string $objectName ) : Scalr\Service\Aws\S3\DataType\AccessControlPolicyData
$bucketName string A bucket name.
$objectName string An object name.
return Scalr\Service\Aws\S3\DataType\AccessControlPolicyData Returns object which describes ACL for the object.
    public function getObjectAcl($bucketName, $objectName)
    {
        $result = null;
        $options = array('_subdomain' => (string) $bucketName);
        $response = $this->client->call('GET', $options, sprintf('/%s?acl', self::escapeObjectName($objectName)));
        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->setObjectName((string) $objectName);
            $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;
    }