Example #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());
 }
Example #2
0
 /**
  * Copy an object to another place in object storage.
  *
  * An object can be copied within a container. Essentially, this will
  * give you duplicates of the file, each with a new name.
  *
  * An object can be copied to another container if the name of the
  * other container is specified, and if that container already exists.
  *
  * Note that there is no MOVE operation. You must copy and then DELETE
  * in order to achieve that.
  *
  * @param object $obj       \OpenStack\ObjectStore\v1\Resource\Object The object to
  *                          copy. This object MUST already be saved on the remote server. The body of
  *                          the object is not sent. Instead, the copy operation is performed on the
  *                          remote server. You can, and probably should, use a RemoteObject here.
  * @param string $newName   The new name of this object. If you are copying a
  *                          cross containers, the name can be the same. If you are copying within
  *                          the same container, though, you will need to supply a new name.
  * @param string $container The name of the alternate container. If this is
  *                          set, the object will be saved into this container. If this is not sent,
  *                          the copy will be performed inside of the original container.
  */
 public function copy(Object $obj, $newName, $container = null)
 {
     $sourceUrl = self::objectUrl($this->url, $obj->name());
     if (empty($newName)) {
         throw new Exception("An object name is required to copy the object.");
     }
     // Figure out what container we store in.
     if (empty($container)) {
         $container = $this->name;
     }
     $container = rawurlencode($container);
     $destUrl = self::objectUrl('/' . $container, $newName);
     $headers = ['X-Auth-Token' => $this->token, 'Destination' => $destUrl, 'Content-Type' => $obj->contentType()];
     $response = $this->client->send($this->client->createRequest('COPY', $sourceUrl, null, ['headers' => $headers]));
     if ($response->getStatusCode() != 201) {
         throw new Exception("An unknown condition occurred during copy. " . $response->getStatusCode());
     }
     return true;
 }