You are here

private function S3::calculateUrlPrefix in Flysystem - S3 8

Same name and namespace in other branches
  1. 2.0.x src/Flysystem/S3.php \Drupal\flysystem_s3\Flysystem\S3::calculateUrlPrefix()

Calculates the URL prefix.

Parameters

\League\Flysystem\Config $config: The configuration.

Return value

string The URL prefix in the form protocol://cname[/bucket][/prefix].

1 call to S3::calculateUrlPrefix()
S3::__construct in src/Flysystem/S3.php
Constructs an S3 object.

File

src/Flysystem/S3.php, line 241

Class

S3
Drupal plugin for the "S3" Flysystem adapter.

Namespace

Drupal\flysystem_s3\Flysystem

Code

private function calculateUrlPrefix(Config $config) {
  $protocol = $config
    ->get('protocol', 'http');
  $cname = (string) $config
    ->get('cname');
  $prefix = (string) $config
    ->get('prefix', '');
  $prefix = $prefix === '' ? '' : '/' . UrlHelper::encodePath($prefix);
  if ($cname !== '' && $config
    ->get('cname_is_bucket', TRUE)) {
    return $protocol . '://' . $cname . $prefix;
  }
  $bucket = (string) $config
    ->get('bucket', '');
  $bucket = $bucket === '' ? '' : '/' . UrlHelper::encodePath($bucket);

  // No custom CNAME was provided. Generate the default S3 one.
  if ($cname === '') {
    $cname = 's3-' . $config
      ->get('region', 'us-east-1') . '.amazonaws.com';
  }

  // us-east-1 doesn't follow the consistent mapping.
  if ($cname === 's3-us-east-1.amazonaws.com') {
    $cname = 's3.amazonaws.com';
  }
  return $protocol . '://' . $cname . $bucket . $prefix;
}