Workingn on object save feature.
This commit is contained in:
@@ -191,7 +191,7 @@ class ObjectStorage {
|
||||
|
||||
$containerList = array();
|
||||
foreach ($containers as $container) {
|
||||
$containerList[$container['name']] = Container::newFromJSON($container, $this->url(), $this->token());
|
||||
$containerList[$container['name']] = Container::newFromJSON($container, $this->token(), $this->url());
|
||||
}
|
||||
|
||||
return $containerList;
|
||||
@@ -216,7 +216,7 @@ class ObjectStorage {
|
||||
|
||||
$status = $data->status();
|
||||
if ($status == 204) {
|
||||
return Container::newFromResponse($name, $data, $this->url(), $this->token());
|
||||
return Container::newFromResponse($name, $data, $this->token(), $this->url());
|
||||
}
|
||||
|
||||
// If we get here, it's not a 404 and it's not a 204.
|
||||
@@ -317,6 +317,11 @@ class ObjectStorage {
|
||||
catch (\HPCloud\Transport\FileNotFoundException $e) {
|
||||
return FALSE;
|
||||
}
|
||||
// XXX: I'm not terribly sure about this. Why not just throw the
|
||||
// ConflictException?
|
||||
catch (\HPCloud\Transport\ConflictException $e) {
|
||||
throw new ObjectStorage\ContainerNotEmptyException("Non-empty container cannot be deleted.");
|
||||
}
|
||||
|
||||
$status = $data->status();
|
||||
|
||||
@@ -324,12 +329,6 @@ class ObjectStorage {
|
||||
if ($status == 204) {
|
||||
return TRUE;
|
||||
}
|
||||
// The container must be empty before it can be deleted. This is an
|
||||
// actual failure, so we throw an exception.
|
||||
elseif ($status == 409) {
|
||||
throw new ObjectStorage\ContainerNotEmptyException("Non-empty container cannot be deleted.");
|
||||
}
|
||||
|
||||
// OpenStacks documentation doesn't suggest any other return
|
||||
// codes.
|
||||
else {
|
||||
|
||||
@@ -179,6 +179,21 @@ class Container implements \Countable {
|
||||
* This takes an \HPCloud\Storage\ObjectStorage\Object
|
||||
* and stores it in the given container in the present
|
||||
* container on the remote object store.
|
||||
*
|
||||
* @param \HPCloud\Storage\ObjectStorage\Object $obj
|
||||
* The object to store.
|
||||
* @return boolean
|
||||
* TRUE if the object was saved.
|
||||
* @throws \HPCloud\Transport\LengthRequiredException
|
||||
* if the Content-Length could not be determined and chunked
|
||||
* encoding was not enabled. This should not occur for this class,
|
||||
* which always automatically generates Content-Length headers.
|
||||
* However, subclasses could generate this error.
|
||||
* @throws \HPCloud\Transport\UnprocessableEntityException
|
||||
* if the checksome passed here does not match the checksum
|
||||
* calculated remotely.
|
||||
* @throws \HPCloud\Exception when an unexpected (usually
|
||||
* network-related) error condition arises.
|
||||
*/
|
||||
public function save(Object $obj) {
|
||||
|
||||
@@ -201,6 +216,8 @@ class Container implements \Countable {
|
||||
// Now build up the rest of the headers:
|
||||
$headers['ETag'] = $obj->eTag();
|
||||
|
||||
// If chunked, we set transfer encoding; else
|
||||
// we set the content length.
|
||||
if ($obj->isChunked()) {
|
||||
// How do we handle this? Does the underlying
|
||||
// stream wrapper pay any attention to this?
|
||||
@@ -210,6 +227,7 @@ class Container implements \Countable {
|
||||
$headers['Content-Length'] = $obj->contentLength();
|
||||
}
|
||||
|
||||
// Auth token.
|
||||
$headers['X-Auth-Token'] = $this->token;
|
||||
|
||||
$client = \HPCloud\Transport::instance();
|
||||
@@ -217,7 +235,6 @@ class Container implements \Countable {
|
||||
$response = $client->doRequest($url, 'PUT', $headers, $obj->content());
|
||||
|
||||
if ($response->status() != 201) {
|
||||
|
||||
throw new \HPCloud\Exception('An unknown error occurred while saving: ' . $response->status());
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
@@ -10,6 +10,7 @@ require_once 'src/HPCloud/Bootstrap.php';
|
||||
require_once 'test/TestCase.php';
|
||||
|
||||
use \HPCloud\Storage\ObjectStorage\Container;
|
||||
use \HPCloud\Storage\ObjectStorage\Object;
|
||||
|
||||
class ContainerTest extends \HPCloud\Tests\TestCase {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user