protected function S3fsStream::convertUriToKeyedPath in S3 File System 8.3
Same name and namespace in other branches
- 4.0.x src/StreamWrapper/S3fsStream.php \Drupal\s3fs\StreamWrapper\S3fsStream::convertUriToKeyedPath()
Converts a Drupal URI path into what is expected to be stored in S3.
Parameters
string $uri: An appropriate URI formatted like 'protocol://path'.
bool $prepend_bucket: Whether to prepend the bucket name. S3's stream wrapper requires this for some functions.
Return value
string A converted string ready for S3 to process it.
5 calls to S3fsStream::convertUriToKeyedPath()
- S3fsStream::getCommandParams in src/
StreamWrapper/ S3fsStream.php - Return bucket and key for a command array.
- S3fsStream::rename in src/
StreamWrapper/ S3fsStream.php - Support for rename().
- S3fsStream::rmdir in src/
StreamWrapper/ S3fsStream.php - Support for rmdir().
- S3fsStream::stream_open in src/
StreamWrapper/ S3fsStream.php - S3fsStream::unlink in src/
StreamWrapper/ S3fsStream.php - Support for unlink().
File
- src/
StreamWrapper/ S3fsStream.php, line 1513
Class
- S3fsStream
- Defines a Drupal s3 (s3://) stream wrapper class.
Namespace
Drupal\s3fs\StreamWrapperCode
protected function convertUriToKeyedPath($uri, $prepend_bucket = TRUE) {
// Remove the protocol.
$parts = explode('://', $uri);
// Remove erroneous leading or trailing, forward-slashes and backslashes.
$parts[1] = trim($parts[1], '\\/');
if (!empty($parts[1])) {
// public:// file are all placed in the s3fs_public_folder.
$public_folder = !empty($this->config['public_folder']) ? $this->config['public_folder'] : 's3fs-public';
$private_folder = !empty($this->config['private_folder']) ? $this->config['private_folder'] : 's3fs-private';
if (StreamWrapperManager::getScheme($uri) == 'public') {
$parts[1] = "{$public_folder}/{$parts[1]}";
}
elseif (StreamWrapperManager::getScheme($uri) == 'private') {
$parts[1] = "{$private_folder}/{$parts[1]}";
}
// If it's set, all files are placed in the root folder.
if (!empty($this->config['root_folder'])) {
$parts[1] = "{$this->config['root_folder']}/{$parts[1]}";
}
// Prepend the uri with a bucket since AWS SDK expects this.
if ($prepend_bucket) {
$parts[1] = $this->config['bucket'] . '/' . $parts[1];
}
}
// Set protocol to S3 so AWS stream wrapper works correctly.
$parts[0] = 's3';
return implode('://', $parts);
}