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

deleteObject() public method

The DELETE operation removes the null version (if there is one) of an object and inserts a delete marker, which becomes the latest version of the object. If there isn't a null version, Amazon S3 does not remove any objects To remove a specific version, you must be the bucket owner and you must use the versionId subresource. Using this subresource permanently deletes the version. If the object deleted is a Delete Marker, Amazon S3 sets the response header, x-amz-delete-marker, to true. If the object you want to delete is in a bucket where the bucket versioning configuration is MFA Delete enabled, you must include the x-amz-mfa request header in the DELETE versionId request. Requests that include x-amz-mfa must use HTTPS.
public deleteObject ( string $bucketName, string $objectName, string $versionId = null, string $xAmfMfa = null ) : Scalr\Service\Aws\Client\ClientResponseInterface
$bucketName string A bucket name.
$objectName string A object name.
$versionId string optional To remove a specific version of the object it must be used.
$xAmfMfa string optional The value is the concatenation of the authentication device's serial number, a space, and the value displayed on your authentication device.
return Scalr\Service\Aws\Client\ClientResponseInterface Returns response on success or throws an exception
    public function deleteObject($bucketName, $objectName, $versionId = null, $xAmfMfa = null)
    {
        $options = array('_subdomain' => (string) $bucketName);
        if ($xAmfMfa !== null) {
            $options['x-amz-mfa'] = (string) $xAmfMfa;
        }
        $response = $this->client->call('DELETE', $options, '/' . self::escapeObjectName($objectName) . ($versionId !== null ? '?versionId=' . self::escape($versionId) : ''));
        if ($response->getError() === false) {
            //Whether request is not to remove specific version.
            if ($versionId === null) {
                //Whether object exists.
                $object = $this->s3->object->get(array((string) $bucketName, $objectName));
                if ($object !== null) {
                    //If exists we should detach it from the storage
                    $this->getEntityManager()->detach($object);
                }
            }
        }
        return $response;
    }