Ejemplo n.º 1
0
 public function testConstructor()
 {
     $o = $this->basicObjectFixture();
     $this->assertEquals(self::FNAME, $o->name());
     $o = new Object('a', 'b', 'text/plain');
     $this->assertEquals('a', $o->name());
     $this->assertEquals('b', $o->content());
     $this->assertEquals('text/plain', $o->contentType());
 }
Ejemplo n.º 2
0
 public function testSave()
 {
     // Clean up anything left.
     $this->destroyContainerFixture();
     $container = $this->containerFixture();
     $object = new Object(self::FNAME, self::FCONTENT, self::FTYPE);
     $object->setMetadata(['foo' => '1234']);
     $this->assertEquals(self::FCONTENT, $object->content());
     try {
         $ret = $container->save($object);
     } catch (\Exception $e) {
         $this->destroyContainerFixture();
         throw $e;
     }
     $this->assertTrue($ret);
 }
Ejemplo n.º 3
0
 /**
  * Update an object's metadata.
  *
  * This updates the metadata on an object without modifying anything
  * else. This is a convenient way to set additional metadata without
  * having to re-upload a potentially large object.
  *
  * Swift's behavior during this operation is sometimes unpredictable,
  * particularly in cases where custom headers have been set.
  * Use with caution.
  *
  * @param object $obj \OpenStack\ObjectStore\v1\Resource\Object The object to update.
  *
  * @return boolean true if the metadata was updated.
  *
  * @throws \OpenStack\Common\Transport\Exception\ResourceNotFoundException if the object does not already
  *                                                           exist on the object storage.
  */
 public function updateMetadata(Object $obj)
 {
     $url = self::objectUrl($this->url, $obj->name());
     $headers = ['X-Auth-Token' => $this->token];
     // See if we have any metadata. We post this even if there
     // is no metadata.
     $metadata = $obj->metadata();
     if (!empty($metadata)) {
         $headers += self::generateMetadataHeaders($metadata, Container::METADATA_HEADER_PREFIX);
     }
     // In spite of the documentation's claim to the contrary,
     // content type IS reset during this operation.
     $headers['Content-Type'] = $obj->contentType();
     // The POST verb is for updating headers.
     $response = $this->client->post($url, $obj->content(), ['headers' => $headers]);
     if ($response->getStatusCode() != 202) {
         throw new Exception(sprintf("An unknown error occurred while saving: %d", $response->status()));
     }
     return true;
 }