You are here

protected function AmazonS3StreamWrapper::getS3 in AmazonS3 7

Get the S3 connection object.

Return value

AmazonS3 S3 connection object (AmazonS3)

See also

http://docs.amazonwebservices.com/AWSSDKforPHP/latest/#i=AmazonS3

3 calls to AmazonS3StreamWrapper::getS3()
AmazonS3StreamWrapper::rename in ./AmazonS3StreamWrapper.inc
Support for rename().
AmazonS3StreamWrapper::stream_flush in ./AmazonS3StreamWrapper.inc
Support for fflush(). Flush current cached stream data to storage.
AmazonS3StreamWrapper::_amazons3_rmdir in ./AmazonS3StreamWrapper.inc
Helper function for deleting directories.

File

./AmazonS3StreamWrapper.inc, line 1081
Drupal stream wrapper implementation for Amazon S3

Class

AmazonS3StreamWrapper
@file Drupal stream wrapper implementation for Amazon S3

Code

protected function getS3() {
  if ($this->s3 === NULL) {
    if (!libraries_load('awssdk')) {
      drupal_set_message(t('Unable to load the AWS SDK. Please check you have installed the library correctly and configured your S3 credentials.') . 'error');
    }
    elseif (empty($this->bucket)) {
      drupal_set_message(t('Bucket name not configured.') . 'error');
    }
    else {
      try {
        $this->s3 = new AmazonS3();
        if (!empty($this->hostname)) {
          $this->s3
            ->set_hostname($this->hostname);
          $this->s3
            ->allow_hostname_override(FALSE);
        }
      } catch (Exception $e) {
        drupal_set_message(t('There was a problem using S3. @message', array(
          'message' => $e
            ->getMessage(),
        )), 'error');
      }
    }
  }
  return $this->s3;
}