Skip to content
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