/** * Updates an object in the cloud. * @param Identifier $id The ID of the object to update * @param Acl $acl Access control list for the new object. Optional, default * is NULL. * @param MetadataList $metadata Metadata list for the new object. Optional, * default is NULL. * @param Extent $extent The extent of the object to update. If extent * is null or ALL_CONTENT and $data is not, the entire object will be * replaced. If $data is null, $extent must also be null. * @param string $data The data of the object. May be appended * to later. Optional, default is NULL (no content). If data is null, * the extent must also be null. * @param string $mimeType the MIME type of the content. Optional, * may be null. If $data is non-null and $mimeType is null, the MIME * type will default to application/octet-stream. * @param Checksum $checksum if not null, use the Checksum object to compute * the checksum for the update object request. If appending * to the object with subsequent requests, use the same * checksum object for each request. * @throws EsuException if the request fails. */ public function updateObject($id, $acl = null, $metadata = null, $extent = null, $data = null, $mimeType = null, $checksum = null) { // Build the request $resource = $this->getResourcePath($this->context, $id); $req = $this->buildRequest($resource, null); $headers = array(); if ($mimeType == null && $data != null) { $mimeType = 'application/octet-stream'; } if (!empty($mimeType)) { $headers['Content-Type'] = $mimeType; } $headers['x-emc-uid'] = $this->uid; // Process metadata if ($metadata != null) { $this->processMetadata($metadata, $headers); } if ($this->utf8) { $headers['x-emc-utf8'] = 'true'; } if (is_a($id, 'Atmos\\Keypool')) { $headers['x-emc-pool'] = $id->getPool(); } // Check extent / data requirements if ($data == null && $extent != null) { throw new EsuException('Cannot specify an extent without data'); } // Add extent if needed if ($extent != null && $extent != Extent::$ALL_CONTENT) { // Need to do bcmath because the value might be > 4GB $end = bcadd($extent->getOffset(), $extent->getSize()); $end = bcsub($end, 1); $headers['Range'] = 'Bytes=' . $extent->getOffset() . '-' . $end; } if (isset($headers['x-emc-meta'])) { $this->trace('meta ' . $headers['x-emc-meta']); } // Add acl if ($acl != null) { $this->processAcl($acl, $headers); } // Process data if ($data != null) { $req->setBody($data); } else { $req->setBody(''); } // Process checksum if ($checksum != null) { if ($data != null) { $checksum->update($data); } $headers['x-emc-wschecksum'] = '' . $checksum; } $headers['Date'] = gmdate('r'); // Sign and send the request $this->signRequest($req, 'PUT', $resource, $headers, $data); try { $response = @$req->send(); } catch (HTTP_Request2_Exception $e) { throw new EsuException('Sending request failed: ' . $e->__toString()); } // Return the response if ($response->getStatus() > 299) { $this->handleError($response); } }
} /** * Returns the starting offset of the extent * @return string the extent's starting offset */ public function getOffset() { return $this->offset; } public function __toString() { return "Extent: offset: {$this->offset} size: {$this->size}\n"; } } // Initialize the ALL_CONTENT instance Extent::$ALL_CONTENT = new Extent(-1, -1); /** * A grantee represents a user or group that recieves a permission grant. */ class Grantee { const USER = '******'; const GROUP = 'GROUP'; /** * Static instance that represents the special group 'other' */ public static $OTHER; private $name; private $type; /** * Creates a new grantee.