Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.5] Adding Rackspace compability to Storage::url() and Storage::temporaryUrl() #21157

Merged
merged 6 commits into from
Sep 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 54 additions & 1 deletion src/Illuminate/Filesystem/FilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use League\Flysystem\FilesystemInterface;
use League\Flysystem\AwsS3v3\AwsS3Adapter;
use League\Flysystem\FileNotFoundException;
use League\Flysystem\Rackspace\RackspaceAdapter;
use League\Flysystem\Adapter\Local as LocalAdapter;
use Illuminate\Contracts\Filesystem\Cloud as CloudFilesystemContract;
use Illuminate\Contracts\Filesystem\Filesystem as FilesystemContract;
Expand Down Expand Up @@ -332,11 +333,25 @@ public function url($path)
return $this->getAwsUrl($adapter, $path);
} elseif ($adapter instanceof LocalAdapter) {
return $this->getLocalUrl($path);
} elseif ($adapter instanceof RackspaceAdapter) {
return $this->getRackspaceUrl($adapter, $path);
} else {
throw new RuntimeException('This driver does not support retrieving URLs.');
}
}

/**
* Get the URL for the file at the given path.
*
* @param \League\Flysystem\Rackspace\RackspaceAdapter $adapter
* @param string $path
* @return string
*/
protected function getRackspaceUrl($adapter, $path)
{
return (string) $adapter->getContainer()->getObject($path)->getPublicUrl();
}

/**
* Get the URL for the file at the given path.
*
Expand Down Expand Up @@ -394,10 +409,48 @@ public function temporaryUrl($path, $expiration, array $options = [])

if (method_exists($adapter, 'getTemporaryUrl')) {
return $adapter->getTemporaryUrl($path, $expiration, $options);
} elseif (! $adapter instanceof AwsS3Adapter) {
} elseif ($adapter instanceof AwsS3Adapter) {
return $this->getAwsTemporaryUrl($adapter, $path, $expiration, $options);
} elseif ($adapter instanceof RackspaceAdapter) {
return $this->getRackspaceTemporaryUrl($adapter, $path, $expiration, $options);
} else {
throw new RuntimeException('This driver does not support creating temporary URLs.');
}
}

/**
* Get a temporary URL for the file at the given path.
*
* @param \League\Flysystem\Rackspace\RackspaceAdapter $adapter
* @param string $path
* @param \DateTimeInterface $expiration
* @param $options
* @return string
*/
public function getRackspaceTemporaryUrl($adapter, $path, $expiration, $options)
{
$seconds = \Carbon\Carbon::now()->diffInSeconds($expiration);

return $adapter
->getContainer()
->getObject($path)
->getTemporaryUrl(
$seconds,
isset($options['method']) ? $options['method'] : 'GET',
isset($options['forcePublicUrl']) ? $options['forcePublicUrl'] : true);
}

/**
* Get a temporary URL for the file at the given path.
*
* @param \League\Flysystem\AwsS3v3\AwsS3Adapter $adapter
* @param string $path
* @param \DateTimeInterface $expiration
* @param array $options
* @return string
*/
public function getAwsTemporaryUrl($adapter, $path, $expiration, $options)
{
$client = $adapter->getClient();

$command = $client->getCommand('GetObject', array_merge([
Expand Down