Skip to content

Commit d6a20ae

Browse files
committed
Flysystem v2
1 parent 91e7a7a commit d6a20ae

File tree

9 files changed

+370
-331
lines changed

9 files changed

+370
-331
lines changed

composer.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"dragonmantank/cron-expression": "^3.0",
2424
"egulias/email-validator": "^2.1.10",
2525
"league/commonmark": "^1.3",
26-
"league/flysystem": "^1.0.34",
26+
"league/flysystem": "^2.0",
2727
"monolog/monolog": "^2.0",
2828
"nesbot/carbon": "^2.17",
2929
"opis/closure": "^3.5.3",
@@ -82,7 +82,9 @@
8282
"doctrine/dbal": "^2.6",
8383
"filp/whoops": "^2.4",
8484
"guzzlehttp/guzzle": "^6.5.5|^7.0.1",
85-
"league/flysystem-cached-adapter": "^1.0",
85+
"league/flysystem-aws-s3-v3": "^2.0",
86+
"league/flysystem-ftp": "^2.0",
87+
"league/flysystem-sftp": "^2.0",
8688
"mockery/mockery": "^1.3.1",
8789
"orchestra/testbench-core": "^6.0",
8890
"pda/pheanstalk": "^4.0",
@@ -133,9 +135,9 @@
133135
"fzaninotto/faker": "Required to use the eloquent factory builder (^1.9.1).",
134136
"guzzlehttp/guzzle": "Required to use the HTTP Client, Mailgun mail driver and the ping methods on schedules (^6.5.5|^7.0.1).",
135137
"laravel/tinker": "Required to use the tinker console command (^2.0).",
136-
"league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (^1.0).",
137-
"league/flysystem-cached-adapter": "Required to use the Flysystem cache (^1.0).",
138-
"league/flysystem-sftp": "Required to use the Flysystem SFTP driver (^1.0).",
138+
"league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (^2.0).",
139+
"league/flysystem-ftp": "Required to use the Flysystem FTP driver (^2.0).",
140+
"league/flysystem-sftp": "Required to use the Flysystem SFTP driver (^2.0).",
139141
"mockery/mockery": "Required to use mocking (^1.3.1).",
140142
"nyholm/psr7": "Required to use PSR-7 bridging features (^1.2).",
141143
"pda/pheanstalk": "Required to use the beanstalk queue driver (^4.0).",

src/Illuminate/Contracts/Filesystem/FileExistsException.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/Illuminate/Contracts/Filesystem/Filesystem.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ public function exists($path);
3030
* Get the contents of a file.
3131
*
3232
* @param string $path
33-
* @return string
34-
*
35-
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
33+
* @return string|null
3634
*/
3735
public function get($path);
3836

@@ -41,8 +39,6 @@ public function get($path);
4139
*
4240
* @param string $path
4341
* @return resource|null The path resource or null on failure.
44-
*
45-
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
4642
*/
4743
public function readStream($path);
4844

@@ -63,9 +59,6 @@ public function put($path, $contents, $options = []);
6359
* @param resource $resource
6460
* @param array $options
6561
* @return bool
66-
*
67-
* @throws \InvalidArgumentException If $resource is not a file handle.
68-
* @throws \Illuminate\Contracts\Filesystem\FileExistsException
6962
*/
7063
public function writeStream($path, $resource, array $options = []);
7164

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
namespace Illuminate\Filesystem;
4+
5+
use Aws\S3\S3Client;
6+
use League\Flysystem\AwsS3V3\AwsS3V3Adapter as S3Adapter;
7+
use League\Flysystem\FilesystemOperator;
8+
9+
class AwsS3V3Adapter extends FilesystemAdapter
10+
{
11+
/**
12+
* The AWS S3 client.
13+
*
14+
* @var S3Client
15+
*/
16+
protected $client;
17+
18+
/**
19+
* Create a new AwsS3V3FilesystemAdapter instance.
20+
*
21+
* @param \League\Flysystem\FilesystemOperator $driver
22+
* @param \League\Flysystem\AwsS3V3\AwsS3V3Adapter $adapter
23+
* @param array $config
24+
* @param \Aws\S3\S3Client $client
25+
* @return void
26+
*/
27+
public function __construct(FilesystemOperator $driver, S3Adapter $adapter, array $config, S3Client $client)
28+
{
29+
parent::__construct($driver, $adapter, $config);
30+
31+
$this->client = $client;
32+
}
33+
34+
/**
35+
* Get the URL for the file at the given path.
36+
*
37+
* @param string $path
38+
* @return string
39+
*
40+
* @throws \RuntimeException
41+
*/
42+
public function url($path)
43+
{
44+
// If an explicit base URL has been set on the disk configuration then we will use
45+
// it as the base URL instead of the default path. This allows the developer to
46+
// have full control over the base path for this filesystem's generated URLs.
47+
if (isset($this->config['url'])) {
48+
return $this->concatPathToUrl($this->config['url'], $this->prefixer->prefixPath($path));
49+
}
50+
51+
return $this->client->getObjectUrl(
52+
$this->config['bucket'], $this->prefixer->prefixPath($path)
53+
);
54+
}
55+
56+
/**
57+
* Get a temporary URL for the file at the given path.
58+
*
59+
* @param string $path
60+
* @param \DateTimeInterface $expiration
61+
* @param array $options
62+
* @return string
63+
*/
64+
public function temporaryUrl($path, $expiration, array $options = [])
65+
{
66+
$command = $this->client->getCommand('GetObject', array_merge([
67+
'Bucket' => $this->config['bucket'],
68+
'Key' => $this->prefixer->prefixPath($path),
69+
], $options));
70+
71+
return (string) $this->client->createPresignedRequest(
72+
$command, $expiration
73+
)->getUri();
74+
}
75+
}

0 commit comments

Comments
 (0)