|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace A17\Twill\Http\ViewComposers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Config\Repository as Config; |
|
6
|
|
|
use Illuminate\Contracts\View\View; |
|
7
|
|
|
use Illuminate\Routing\UrlGenerator; |
|
8
|
|
|
use Illuminate\Session\Store as SessionStore; |
|
9
|
|
|
|
|
10
|
|
|
class FilesUploaderConfig |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var UrlGenerator |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $urlGenerator; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var Config |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $config; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var SessionStore |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $sessionStore; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param UrlGenerator $urlGenerator |
|
29
|
|
|
* @param Config $config |
|
30
|
|
|
* @param SessionStore $sessionStore |
|
31
|
|
|
*/ |
|
32
|
49 |
|
public function __construct(UrlGenerator $urlGenerator, Config $config, SessionStore $sessionStore) |
|
33
|
|
|
{ |
|
34
|
49 |
|
$this->urlGenerator = $urlGenerator; |
|
35
|
49 |
|
$this->config = $config; |
|
36
|
49 |
|
$this->sessionStore = $sessionStore; |
|
37
|
49 |
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Binds data to the view. |
|
41
|
|
|
* |
|
42
|
|
|
* @param View $view |
|
43
|
|
|
* @return void |
|
44
|
|
|
*/ |
|
45
|
49 |
|
public function compose(View $view) |
|
46
|
|
|
{ |
|
47
|
49 |
|
$libraryDisk = $this->config->get('twill.file_library.disk'); |
|
48
|
49 |
|
$endpointType = $this->config->get('twill.file_library.endpoint_type'); |
|
49
|
49 |
|
$allowedExtensions = $this->config->get('twill.file_library.allowed_extensions'); |
|
50
|
|
|
|
|
51
|
|
|
// anonymous functions are used to let configuration dictate |
|
52
|
|
|
// the execution of the appropriate implementation |
|
53
|
|
|
$endpointByType = [ |
|
54
|
49 |
|
'local' => function () { |
|
55
|
49 |
|
return $this->urlGenerator->route('admin.file-library.files.store'); |
|
56
|
49 |
|
}, |
|
57
|
49 |
|
's3' => function () use ($libraryDisk) { |
|
58
|
|
|
return s3Endpoint($libraryDisk); |
|
59
|
49 |
|
}, |
|
60
|
49 |
|
'azure' => function () use ($libraryDisk) { |
|
61
|
|
|
return azureEndpoint($libraryDisk); |
|
62
|
49 |
|
}, |
|
63
|
|
|
]; |
|
64
|
|
|
|
|
65
|
|
|
$signatureEndpointByType = [ |
|
66
|
49 |
|
'local' => null, |
|
67
|
49 |
|
's3' => $this->urlGenerator->route('admin.file-library.sign-s3-upload'), |
|
68
|
49 |
|
'azure' => $this->urlGenerator->route('admin.file-library.sign-azure-upload'), |
|
69
|
|
|
]; |
|
70
|
|
|
|
|
71
|
|
|
$filesUploaderConfig = [ |
|
72
|
49 |
|
'endpointType' => $endpointType, |
|
73
|
49 |
|
'endpoint' => $endpointByType[$endpointType](), |
|
74
|
49 |
|
'successEndpoint' => $this->urlGenerator->route('admin.file-library.files.store'), |
|
75
|
49 |
|
'signatureEndpoint' => $signatureEndpointByType[$endpointType], |
|
76
|
49 |
|
'endpointBucket' => $this->config->get('filesystems.disks.' . $libraryDisk . '.bucket', 'none'), |
|
77
|
49 |
|
'endpointRegion' => $this->config->get('filesystems.disks.' . $libraryDisk . '.region', 'none'), |
|
78
|
49 |
|
'endpointRoot' => $endpointType === 'local' ? '' : $this->config->get('filesystems.disks.' . $libraryDisk . '.root', ''), |
|
79
|
49 |
|
'accessKey' => $this->config->get('filesystems.disks.' . $libraryDisk . '.key', 'none'), |
|
80
|
49 |
|
'csrfToken' => $this->sessionStore->token(), |
|
81
|
49 |
|
'acl' => $this->config->get('twill.file_library.acl'), |
|
82
|
49 |
|
'filesizeLimit' => $this->config->get('twill.file_library.filesize_limit'), |
|
83
|
49 |
|
'allowedExtensions' => $allowedExtensions, |
|
84
|
|
|
]; |
|
85
|
|
|
|
|
86
|
49 |
|
$view->with(compact('filesUploaderConfig')); |
|
87
|
49 |
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|