/**
  * Returns a list of content readers for a given s3 folder
  * 
  * @return \S3ContentReader
  */
 public function getList()
 {
     if ($this->isListable()) {
         $objects = $this->s3Service->listObjects(array("Bucket" => $this->bucket, "Prefix" => $this->getId(), 'return_prefixes' => true, 'Delimiter' => '/'));
         $list = array();
         if (isset($objects['CommonPrefixes'])) {
             foreach ($objects['CommonPrefixes'] as $folder) {
                 $id = $this->getSourceIdentifier() . ContentService::SEPARATOR . $folder['Prefix'];
                 $new = singleton('ContentService')->getReader($id);
                 $new->s3Service = $this->s3Service;
                 $new->bucket = $this->bucket;
                 $new->baseUrl = $this->baseUrl;
                 $list[] = $new;
             }
         }
         if (isset($objects['Contents'])) {
             foreach ($objects['Contents'] as $object) {
                 $name = $object['Key'];
                 if ($name == $this->getId()) {
                     continue;
                 }
                 $id = $this->getSourceIdentifier() . ContentService::SEPARATOR . $name;
                 $new = singleton('ContentService')->getReader($id);
                 $new->s3Service = $this->s3Service;
                 $new->bucket = $this->bucket;
                 $new->baseUrl = $this->baseUrl;
                 $new->setS3Info($object);
                 $list[] = $new;
             }
         }
         return $list;
     }
     return array();
 }
 protected function listId($id)
 {
     if ($this->listedItems) {
         return $this->listedItems;
     }
     if ($id === '/') {
         $id = '';
     }
     $this->listedItems = $this->s3Service->listObjects(array("Bucket" => $this->bucket, "Prefix" => $id, 'return_prefixes' => true, 'Delimiter' => '/'));
     return $this->listedItems;
 }
Пример #3
0
 public function listS3Objects()
 {
     try {
         $client = new S3Client();
         $result = $client->listObjects(array('marker' => $this->get('marker'), 'prefix' => $this->get('prefix'), 'maxkeys' => $this->get('maxkeys') | 100));
         $this->success($result);
     } catch (S3Exception $e) {
         $this->error($e->getMessage());
     } catch (AwsException $e) {
         // This catches the more generic AwsException. You can grab information
         // from the exception using methods of the exception object.
         $this->error(array($e->getAwsRequestId(), $e->getAwsErrorType(), $e->getAwsErrorCode()));
     }
 }