-
Notifications
You must be signed in to change notification settings - Fork 140
Expand file tree
/
Copy pathGCS.php
More file actions
85 lines (75 loc) · 1.85 KB
/
GCS.php
File metadata and controls
85 lines (75 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
namespace Codesleeve\Stapler\Storage;
use Codesleeve\Stapler\Interfaces\Storage as StorageInterface;
use Codesleeve\Stapler\Attachment;
use League\Flysystem\Filesystem;
class GCS implements StorageInterface
{
/**
* The current attachedFile object being processed.
*
* @var \Codesleeve\Stapler\Attachment
*/
public $attachedFile;
/**
* The AWS S3Client instance.
*
* @var Filesystem
*/
protected $filesystem;
/**
* Constructor method.
*
* @param Attachment $attachedFile
* @param Filesystem $filesystem
*/
public function __construct(Attachment $attachedFile, Filesystem $filesystem)
{
$this->attachedFile = $attachedFile;
$this->filesystem = $filesystem;
}
/**
* Return the url for a file upload.
*
* @param string $styleName
*
* @return string
*/
public function url($styleName)
{
return $this->filesystem->getAdapter()->getUrl($this->path($styleName));
}
/**
* Return the key the uploaded file object is stored under within a bucket.
*
* @param string $styleName
*
* @return string
*/
public function path($styleName)
{
return $this->attachedFile->getInterpolator()->interpolate($this->attachedFile->path, $this->attachedFile, $styleName);
}
/**
* Remove an attached file.
*
* @param array $filePaths
*/
public function remove(array $filePaths)
{
if ($filePaths) {
$this->filesystem->delete($filePaths);
}
}
/**
* Move an uploaded file to it's intended destination.
*
* @param string $file
* @param string $filePath
*/
public function move($file, $filePath)
{
$this->filesystem->put($filePath, fopen($file, 'r+'));
unlink($file);
}
}