コード例 #1
0
 /**
  * (non-PHPdoc)
  * @see ObjectStorage_Abstract::update()
  */
 public function update()
 {
     $headers = $this->request->getHeaders();
     if (count($headers) > 0) {
         foreach ($headers as $key => $value) {
             if (in_array(strtoupper($key), self::$skipOverwriteHeaders)) {
                 $this->request->deleteHeader($key);
             }
         }
     }
     $this->request->setHeader('Content-Length', strlen($this->request->getBody()));
     return parent::update();
 }
コード例 #2
0
 /**
  * (non-PHPdoc)
  * @see ObjectStorage_Abstract::get()
  */
 public function get($limit = 100, $marker = '')
 {
     parent::get($limit, $marker);
     if ($this->response->getBody() == '') {
         return $this;
     }
     switch (strtoupper($this->mime)) {
         case ObjectStorage::MIME_JSON:
             $objects = json_decode($this->response->getBody());
             if (count($objects) > 0) {
                 foreach ($objects as $object) {
                     if ($this->context == ObjectStorage_Abstract::CONTEXT_SEARCH) {
                         $path = $object->type == 'container' ? $object->container : $object->container . '/' . $object->name;
                     } else {
                         $path = $this->path . '/' . (isset($object->name) ? $object->name : (isset($object->subdir) ? $object->subdir : ''));
                     }
                     $this->appendData($this->objectStorage->with($path));
                 }
             }
             break;
         case ObjectStorage::MIME_XML:
             // @todo implement this
             $data = simplexml_load_string($this->response->getBody());
             $loopData = count($data->object) > 0 ? $data->object : (count($data->container) > 0 ? $data->container : array());
             if (count($loopData) > 0) {
                 if ($this->context == ObjectStorage_Abstract::CONTEXT_SEARCH) {
                     foreach ($loopData as $object) {
                         $path = (string) $object->type == 'container' ? $object->container : $object->container . '/' . $object->name;
                         $this->appendData($this->objectStorage->with($path));
                     }
                 } else {
                     foreach ($loopData as $object) {
                         $this->appendData($this->objectStorage->with($this->path . '/' . (string) $object->name));
                     }
                 }
             }
             break;
         default:
             // plain/text
             $objects = explode("\n", trim($this->response->getBody(), "\n"));
             if (count($objects) > 0) {
                 $path = $this->path == '' ? '' : trim($this->path, '/') . '/';
                 foreach ($objects as $object) {
                     $this->appendData($this->objectStorage->with($path . $object));
                 }
             }
     }
     if ($this->context == ObjectStorage_Abstract::CONTEXT_SEARCH) {
         $this->containerCount = count($this->containers);
         $this->objectCount = count($this->objects);
     }
     return $this;
 }
コード例 #3
0
 /**
  * Deletes a ObjectStorage container or an object
  *
  * @param ObjectStorage_Abstract $objectStorageObject
  *
  * @return bool
  */
 public function delete(ObjectStorage_Abstract $objectStorageObject)
 {
     $authData = $this->getAuthenticationData();
     $uri = $authData->objectStorageUrl . '/' . rawurlencode($objectStorageObject->getPath());
     $queryParams = array();
     if (count($objectStorageObject->queryString) > 0) {
         foreach ($objectStorageObject->queryString as $key => $value) {
             $queryParams[] = $key . '=' . urlencode($value);
         }
         $uri .= '?' . implode('&', $queryParams);
     }
     $client = $this->getHttpClient();
     $client->setHeaders('X-Auth-Token', $authData->authToken);
     $client->setMethod('DELETE');
     $client->setUri($uri);
     $response = $client->request();
     if ($this->isAcceptableResponse($response->getStatusCode())) {
         $objectStorageObject->setResponse($response);
         return true;
     } else {
         throw ObjectStorage_Exception_Http::factory(null, $response->getStatusCode());
     }
 }