/**
  * @return S3Client
  */
 public function connect()
 {
     if (!$this->client) {
         // Create an Amazon S3 client object
         $this->client = S3Client::factory(array('key' => $this->key, 'secret' => $this->secret));
         if ($this->region) {
             $this->client->setRegion($this->region);
         }
         // Register the stream wrapper from a client object
         $this->client->registerStreamWrapper();
         $this->scheme = 's3://' . $this->bucketName;
         if (file_exists($this->scheme)) {
             $this->scheme .= '/' . $this->baseFolder;
             if (!file_exists($this->scheme)) {
                 $this->filesystem->mkdir($this->scheme);
             }
         } else {
             throw new \Exception('Bucket ' . $this->bucketName . ' missing.');
         }
     }
     return $this->client;
 }
示例#2
0
 public function setUp()
 {
     $this->client = $this->getServiceBuilder()->get('s3', true);
     $this->bucket = self::getResourcePrefix() . '-s3-test';
     $this->client->setRegion('us-west-2');
 }