@@ -29,72 +29,72 @@ |
||
29 | 29 | const S3_UPLOAD_PART_SIZE = 524288000; // 500MB |
30 | 30 | |
31 | 31 | trait S3ObjectTrait { |
32 | - /** |
|
33 | - * Returns the connection |
|
34 | - * |
|
35 | - * @return S3Client connected client |
|
36 | - * @throws \Exception if connection could not be made |
|
37 | - */ |
|
38 | - abstract protected function getConnection(); |
|
32 | + /** |
|
33 | + * Returns the connection |
|
34 | + * |
|
35 | + * @return S3Client connected client |
|
36 | + * @throws \Exception if connection could not be made |
|
37 | + */ |
|
38 | + abstract protected function getConnection(); |
|
39 | 39 | |
40 | - /** |
|
41 | - * @param string $urn the unified resource name used to identify the object |
|
42 | - * @return resource stream with the read data |
|
43 | - * @throws \Exception when something goes wrong, message will be logged |
|
44 | - * @since 7.0.0 |
|
45 | - */ |
|
46 | - function readObject($urn) { |
|
47 | - $client = $this->getConnection(); |
|
48 | - $command = $client->getCommand('GetObject', [ |
|
49 | - 'Bucket' => $this->bucket, |
|
50 | - 'Key' => $urn |
|
51 | - ]); |
|
52 | - $request = \Aws\serialize($command); |
|
53 | - $headers = []; |
|
54 | - foreach ($request->getHeaders() as $key => $values) { |
|
55 | - foreach ($values as $value) { |
|
56 | - $headers[] = "$key: $value"; |
|
57 | - } |
|
58 | - } |
|
59 | - $opts = [ |
|
60 | - 'http' => [ |
|
61 | - 'header' => $headers |
|
62 | - ] |
|
63 | - ]; |
|
40 | + /** |
|
41 | + * @param string $urn the unified resource name used to identify the object |
|
42 | + * @return resource stream with the read data |
|
43 | + * @throws \Exception when something goes wrong, message will be logged |
|
44 | + * @since 7.0.0 |
|
45 | + */ |
|
46 | + function readObject($urn) { |
|
47 | + $client = $this->getConnection(); |
|
48 | + $command = $client->getCommand('GetObject', [ |
|
49 | + 'Bucket' => $this->bucket, |
|
50 | + 'Key' => $urn |
|
51 | + ]); |
|
52 | + $request = \Aws\serialize($command); |
|
53 | + $headers = []; |
|
54 | + foreach ($request->getHeaders() as $key => $values) { |
|
55 | + foreach ($values as $value) { |
|
56 | + $headers[] = "$key: $value"; |
|
57 | + } |
|
58 | + } |
|
59 | + $opts = [ |
|
60 | + 'http' => [ |
|
61 | + 'header' => $headers |
|
62 | + ] |
|
63 | + ]; |
|
64 | 64 | |
65 | - $context = stream_context_create($opts); |
|
66 | - return fopen($request->getUri(), 'r', false, $context); |
|
67 | - } |
|
65 | + $context = stream_context_create($opts); |
|
66 | + return fopen($request->getUri(), 'r', false, $context); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @param string $urn the unified resource name used to identify the object |
|
71 | - * @param resource $stream stream with the data to write |
|
72 | - * @throws \Exception when something goes wrong, message will be logged |
|
73 | - * @since 7.0.0 |
|
74 | - */ |
|
75 | - function writeObject($urn, $stream) { |
|
76 | - $uploader = new MultipartUploader($this->getConnection(), $stream, [ |
|
77 | - 'bucket' => $this->bucket, |
|
78 | - 'key' => $urn, |
|
79 | - 'part_size' => S3_UPLOAD_PART_SIZE |
|
80 | - ]); |
|
81 | - $uploader->upload(); |
|
82 | - } |
|
69 | + /** |
|
70 | + * @param string $urn the unified resource name used to identify the object |
|
71 | + * @param resource $stream stream with the data to write |
|
72 | + * @throws \Exception when something goes wrong, message will be logged |
|
73 | + * @since 7.0.0 |
|
74 | + */ |
|
75 | + function writeObject($urn, $stream) { |
|
76 | + $uploader = new MultipartUploader($this->getConnection(), $stream, [ |
|
77 | + 'bucket' => $this->bucket, |
|
78 | + 'key' => $urn, |
|
79 | + 'part_size' => S3_UPLOAD_PART_SIZE |
|
80 | + ]); |
|
81 | + $uploader->upload(); |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * @param string $urn the unified resource name used to identify the object |
|
86 | - * @return void |
|
87 | - * @throws \Exception when something goes wrong, message will be logged |
|
88 | - * @since 7.0.0 |
|
89 | - */ |
|
90 | - function deleteObject($urn) { |
|
91 | - $this->getConnection()->deleteObject([ |
|
92 | - 'Bucket' => $this->bucket, |
|
93 | - 'Key' => $urn |
|
94 | - ]); |
|
95 | - } |
|
84 | + /** |
|
85 | + * @param string $urn the unified resource name used to identify the object |
|
86 | + * @return void |
|
87 | + * @throws \Exception when something goes wrong, message will be logged |
|
88 | + * @since 7.0.0 |
|
89 | + */ |
|
90 | + function deleteObject($urn) { |
|
91 | + $this->getConnection()->deleteObject([ |
|
92 | + 'Bucket' => $this->bucket, |
|
93 | + 'Key' => $urn |
|
94 | + ]); |
|
95 | + } |
|
96 | 96 | |
97 | - public function objectExists($urn) { |
|
98 | - return $this->getConnection()->doesObjectExist($this->bucket, $urn); |
|
99 | - } |
|
97 | + public function objectExists($urn) { |
|
98 | + return $this->getConnection()->doesObjectExist($this->bucket, $urn); |
|
99 | + } |
|
100 | 100 | } |