Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Filesystem;
4
 
5
use Aws\S3\S3Client;
6
use Illuminate\Support\Traits\Conditionable;
7
use League\Flysystem\AwsS3V3\AwsS3V3Adapter as S3Adapter;
8
use League\Flysystem\FilesystemOperator;
9
 
10
class AwsS3V3Adapter extends FilesystemAdapter
11
{
12
    use Conditionable;
13
 
14
    /**
15
     * The AWS S3 client.
16
     *
17
     * @var \Aws\S3\S3Client
18
     */
19
    protected $client;
20
 
21
    /**
22
     * Create a new AwsS3V3FilesystemAdapter instance.
23
     *
24
     * @param  \League\Flysystem\FilesystemOperator  $driver
25
     * @param  \League\Flysystem\AwsS3V3\AwsS3V3Adapter  $adapter
26
     * @param  array  $config
27
     * @param  \Aws\S3\S3Client  $client
28
     * @return void
29
     */
30
    public function __construct(FilesystemOperator $driver, S3Adapter $adapter, array $config, S3Client $client)
31
    {
32
        parent::__construct($driver, $adapter, $config);
33
 
34
        $this->client = $client;
35
    }
36
 
37
    /**
38
     * Get the URL for the file at the given path.
39
     *
40
     * @param  string  $path
41
     * @return string
42
     *
43
     * @throws \RuntimeException
44
     */
45
    public function url($path)
46
    {
47
        // If an explicit base URL has been set on the disk configuration then we will use
48
        // it as the base URL instead of the default path. This allows the developer to
49
        // have full control over the base path for this filesystem's generated URLs.
50
        if (isset($this->config['url'])) {
51
            return $this->concatPathToUrl($this->config['url'], $this->prefixer->prefixPath($path));
52
        }
53
 
54
        return $this->client->getObjectUrl(
55
            $this->config['bucket'], $this->prefixer->prefixPath($path)
56
        );
57
    }
58
 
59
    /**
60
     * Determine if temporary URLs can be generated.
61
     *
62
     * @return bool
63
     */
64
    public function providesTemporaryUrls()
65
    {
66
        return true;
67
    }
68
 
69
    /**
70
     * Get a temporary URL for the file at the given path.
71
     *
72
     * @param  string  $path
73
     * @param  \DateTimeInterface  $expiration
74
     * @param  array  $options
75
     * @return string
76
     */
77
    public function temporaryUrl($path, $expiration, array $options = [])
78
    {
79
        $command = $this->client->getCommand('GetObject', array_merge([
80
            'Bucket' => $this->config['bucket'],
81
            'Key' => $this->prefixer->prefixPath($path),
82
        ], $options));
83
 
84
        $uri = $this->client->createPresignedRequest(
85
            $command, $expiration, $options
86
        )->getUri();
87
 
88
        // If an explicit base URL has been set on the disk configuration then we will use
89
        // it as the base URL instead of the default path. This allows the developer to
90
        // have full control over the base path for this filesystem's generated URLs.
91
        if (isset($this->config['temporary_url'])) {
92
            $uri = $this->replaceBaseUrl($uri, $this->config['temporary_url']);
93
        }
94
 
95
        return (string) $uri;
96
    }
97
 
98
    /**
99
     * Get the underlying S3 client.
100
     *
101
     * @return \Aws\S3\S3Client
102
     */
103
    public function getClient()
104
    {
105
        return $this->client;
106
    }
107
}