Skip to content

Commit

Permalink
add the url method for sanity
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Feb 8, 2016
1 parent e912113 commit ef81c53
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Illuminate/Filesystem/FilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Support\Collection;
use League\Flysystem\AdapterInterface;
use League\Flysystem\FilesystemInterface;
use League\Flysystem\AwsS3v3\AwsS3Adapter;
use League\Flysystem\FileNotFoundException;
use Illuminate\Contracts\Filesystem\Filesystem as FilesystemContract;
use Illuminate\Contracts\Filesystem\Cloud as CloudFilesystemContract;
Expand Down Expand Up @@ -215,6 +216,23 @@ public function lastModified($path)
return $this->driver->getTimestamp($path);
}

/**
* Get the URL for the file at the given path.
*
* @param string $path
* @return string
*/
public function url($path)
{
if (! $this->driver->getAdapter() instanceof AwsS3Adapter) {
throw new RuntimeException("This driver does not support retrieving URLs.");
}

$bucket = $this->driver->getAdapter()->getBucket();

return $this->driver->getAdapter()->getClient()->getObjectUrl($bucket, $path);
}

/**
* Get an array of all files in a directory.
*
Expand Down

4 comments on commit ef81c53

@vlakoff
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could have just done:

$adapter = $this->driver->getAdapter();

if (! $adapter instanceof AwsS3Adapter) {
    throw new RuntimeException('This driver does not support retrieving URLs.');
}

return $adapter->getClient()->getObjectUrl($adapter->getBucket(), $path);

@phanan
Copy link
Contributor

@phanan phanan commented on ef81c53 Feb 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or two more lines shorter 😄

if (! ($adapter = $this->driver->getAdapter()) instanceof AwsS3Adapter) {
    throw new RuntimeException('This driver does not support retrieving URLs.');
}

return $adapter->getClient()->getObjectUrl($adapter->getBucket(), $path);

@GrahamCampbell
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or two more lines shorter

Assigment in logical statenents shiuld generally be avoided though.

@phanan
Copy link
Contributor

@phanan phanan commented on ef81c53 Feb 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assigment in logical statenents shiuld generally be avoided though.

Indeed. My point was just the "shorter" part, which is not necessarily "better."

Please sign in to comment.