You are here

public function S3FileOriginLocator::getS3FileSource in Acquia Content Hub 8.2

Returns the source of the s3 file.

Parameters

string $uri: The s3 originated file uri.

Return value

array The s3 source with the bucket and root_folder.

Throws

\Exception

File

modules/acquia_contenthub_s3/src/S3FileOriginLocator.php, line 77

Class

S3FileOriginLocator
Responsible for locating the s3 source of the given file url.

Namespace

Drupal\acquia_contenthub_s3

Code

public function getS3FileSource(string $uri) : array {
  $target_uri = StreamWrapperManager::getTarget($uri);
  if ($target_uri) {
    $uri = $target_uri;
  }
  $uri = $this
    ->getOriginalFileUrl($uri);
  $tracked_s3_file = $this->s3FileMap
    ->getFileByUri($uri);
  if (!$tracked_s3_file) {
    $tracked_s3_file = $this
      ->getRemoteFile($uri);
    if (!$tracked_s3_file) {
      return $this
        ->getLocalS3FileSource();
    }
  }
  if ($this->chConfig
    ->get('origin') === $tracked_s3_file->origin_uuid) {
    return $this
      ->getLocalS3FileSource();
  }
  return [
    'bucket' => $tracked_s3_file->bucket,
    'root_folder' => $tracked_s3_file->root_folder,
  ];
}