|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jobtech\LaravelChunky; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Config\Repository; |
|
6
|
|
|
use Illuminate\Support\Arr; |
|
7
|
|
|
use Illuminate\Support\Str; |
|
8
|
|
|
use Jobtech\LaravelChunky\Contracts\MergeHandler; |
|
9
|
|
|
use Jobtech\LaravelChunky\Exceptions\ChunkyException; |
|
10
|
|
|
|
|
11
|
|
|
class ChunkySettings |
|
12
|
|
|
{ |
|
13
|
|
|
/** @var int */ |
|
14
|
|
|
const INDEX_ZERO = 0; |
|
15
|
|
|
|
|
16
|
|
|
/** @var int */ |
|
17
|
|
|
const INDEX_ONE = 1; |
|
18
|
|
|
|
|
19
|
|
|
private ?MergeHandler $handler = null; |
|
20
|
|
|
|
|
21
|
|
|
/** @var array */ |
|
22
|
|
|
private $config; |
|
23
|
|
|
|
|
24
|
|
|
public function __construct(Repository $config) |
|
25
|
|
|
{ |
|
26
|
|
|
$this->config = $config->get('chunky'); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Retrieve the chunky configurations. |
|
31
|
|
|
* |
|
32
|
|
|
* @return array |
|
33
|
|
|
*/ |
|
34
|
|
|
public function config(): array |
|
35
|
|
|
{ |
|
36
|
|
|
return $this->config; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Retrieve the default chunks disk. |
|
41
|
|
|
* |
|
42
|
|
|
* @return string|null |
|
43
|
|
|
*/ |
|
44
|
|
|
public function chunksDisk(): ?string |
|
45
|
|
|
{ |
|
46
|
|
|
return Arr::get($this->config, 'disks.chunks.disk'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Retrieve the chunks destination folder. |
|
51
|
|
|
* |
|
52
|
|
|
* @return string |
|
53
|
|
|
*/ |
|
54
|
|
|
public function chunksFolder(): string |
|
55
|
|
|
{ |
|
56
|
|
|
$folder = Arr::get($this->config, 'disks.chunks.folder'); |
|
57
|
|
|
|
|
58
|
|
|
if ($folder === null) { |
|
59
|
|
|
return ''; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
if (! Str::endsWith($folder, '/')) { |
|
63
|
|
|
$folder .= DIRECTORY_SEPARATOR; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return $folder; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Retrieve the default merge file disk. |
|
71
|
|
|
* |
|
72
|
|
|
* @return string|null |
|
73
|
|
|
*/ |
|
74
|
|
|
public function mergeDisk(): ?string |
|
75
|
|
|
{ |
|
76
|
|
|
return Arr::get($this->config, 'disks.merge.disk'); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Retrieve the merge file destination folder. |
|
81
|
|
|
* |
|
82
|
|
|
* @return string |
|
83
|
|
|
*/ |
|
84
|
|
|
public function mergeFolder(): string |
|
85
|
|
|
{ |
|
86
|
|
|
$folder = Arr::get($this->config, 'disks.merge.folder'); |
|
87
|
|
|
|
|
88
|
|
|
if ($folder === null) { |
|
89
|
|
|
return ''; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
if (! Str::endsWith($folder, '/')) { |
|
93
|
|
|
$folder .= DIRECTORY_SEPARATOR; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
return $folder; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Retrieve the default index value for chunks. |
|
101
|
|
|
* |
|
102
|
|
|
* @return int |
|
103
|
|
|
*/ |
|
104
|
|
|
public function defaultIndex(): int |
|
105
|
|
|
{ |
|
106
|
|
|
return Arr::get($this->config, 'index', self::INDEX_ZERO) |
|
107
|
|
|
?: self::INDEX_ZERO; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Retrieve the additional options for chunk store. |
|
112
|
|
|
* |
|
113
|
|
|
* @return array |
|
114
|
|
|
*/ |
|
115
|
|
|
public function additionalChunksOptions(): array |
|
116
|
|
|
{ |
|
117
|
|
|
return Arr::get($this->config, 'options.chunks', []); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Retrieve the additional options for merge store. |
|
122
|
|
|
* |
|
123
|
|
|
* @return array |
|
124
|
|
|
*/ |
|
125
|
|
|
public function additionalMergeOptions(): array |
|
126
|
|
|
{ |
|
127
|
|
|
return Arr::get($this->config, 'options.merge', []); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Retrieve the auto merge option. |
|
132
|
|
|
* |
|
133
|
|
|
* @return bool |
|
134
|
|
|
*/ |
|
135
|
|
|
public function autoMerge(): bool |
|
136
|
|
|
{ |
|
137
|
|
|
return Arr::get($this->config, 'auto_merge', false); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Retrieve the default merge handler. |
|
142
|
|
|
* |
|
143
|
|
|
* @return MergeHandler |
|
144
|
|
|
*/ |
|
145
|
|
|
public function mergeHandler(): MergeHandler |
|
146
|
|
|
{ |
|
147
|
|
|
if ($this->handler === null) { |
|
148
|
|
|
$handler = Arr::get($this->config, 'merge.handler'); |
|
149
|
|
|
|
|
150
|
|
|
if (! class_exists($handler)) { |
|
151
|
|
|
throw new ChunkyException("Undefined handler $handler"); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
$this->handler = $handler::instance(); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
return $this->handler; |
|
|
|
|
|
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* Retrieve the queue connection for the merge job. |
|
162
|
|
|
* |
|
163
|
|
|
* @return string |
|
164
|
|
|
*/ |
|
165
|
|
|
public function connection() |
|
166
|
|
|
{ |
|
167
|
|
|
return Arr::get($this->config, 'merge.connection'); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* Retrieve the queue for the merge job. |
|
172
|
|
|
* |
|
173
|
|
|
* @return array|\ArrayAccess|mixed |
|
174
|
|
|
*/ |
|
175
|
|
|
public function queue() |
|
176
|
|
|
{ |
|
177
|
|
|
return Arr::get($this->config, 'merge.queue'); |
|
178
|
|
|
} |
|
179
|
|
|
} |
|
180
|
|
|
|