|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Publiux\laravelcdn; |
|
4
|
|
|
|
|
5
|
|
|
use Publiux\laravelcdn\Contracts\AssetInterface; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class Asset |
|
9
|
|
|
* Class Asset used to parse and hold all assets and |
|
10
|
|
|
* paths related data and configurations. |
|
11
|
|
|
* |
|
12
|
|
|
* @category DTO |
|
13
|
|
|
* |
|
14
|
|
|
* @author Mahmoud Zalt <[email protected]> |
|
15
|
|
|
*/ |
|
16
|
|
|
class Asset implements AssetInterface |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* default [include] configurations. |
|
20
|
|
|
* |
|
21
|
|
|
* @var array |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $default_include = [ |
|
24
|
|
|
'directories' => ['public'], |
|
25
|
|
|
'extensions' => [], |
|
26
|
|
|
'patterns' => [], |
|
27
|
|
|
]; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* default [exclude] configurations. |
|
31
|
|
|
* |
|
32
|
|
|
* @var array |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $default_exclude = [ |
|
35
|
|
|
'directories' => [], |
|
36
|
|
|
'files' => [], |
|
37
|
|
|
'extensions' => [], |
|
38
|
|
|
'patterns' => [], |
|
39
|
|
|
'hidden' => true, |
|
40
|
|
|
]; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var array |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $included_directories; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var array |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $included_files; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @var array |
|
54
|
|
|
*/ |
|
55
|
|
|
protected $included_extensions; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @var array |
|
59
|
|
|
*/ |
|
60
|
|
|
protected $included_patterns; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @var array |
|
64
|
|
|
*/ |
|
65
|
|
|
protected $excluded_directories; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @var array |
|
69
|
|
|
*/ |
|
70
|
|
|
protected $excluded_files; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @var array |
|
74
|
|
|
*/ |
|
75
|
|
|
protected $excluded_extensions; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @var array |
|
79
|
|
|
*/ |
|
80
|
|
|
protected $excluded_patterns; |
|
81
|
|
|
|
|
82
|
|
|
/* |
|
83
|
|
|
* @var boolean |
|
84
|
|
|
*/ |
|
85
|
|
|
protected $exclude_hidden; |
|
86
|
|
|
|
|
87
|
|
|
/* |
|
88
|
|
|
* Allowed assets for upload (found in included_directories) |
|
89
|
|
|
* |
|
90
|
|
|
* @var Collection |
|
91
|
|
|
*/ |
|
92
|
|
|
public $assets; |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* build a Asset object that contains the assets related configurations. |
|
96
|
|
|
* |
|
97
|
|
|
* @param array $configurations |
|
98
|
|
|
* |
|
99
|
|
|
* @return $this |
|
100
|
|
|
*/ |
|
101
|
|
|
public function init($configurations = []) |
|
102
|
|
|
{ |
|
103
|
|
|
$this->parseAndFillConfiguration($configurations); |
|
104
|
|
|
|
|
105
|
|
|
$this->included_directories = $this->default_include['directories']; |
|
106
|
|
|
$this->included_extensions = $this->default_include['extensions']; |
|
107
|
|
|
$this->included_patterns = $this->default_include['patterns']; |
|
108
|
|
|
|
|
109
|
|
|
$this->excluded_directories = $this->default_exclude['directories']; |
|
110
|
|
|
$this->excluded_files = $this->default_exclude['files']; |
|
111
|
|
|
$this->excluded_extensions = $this->default_exclude['extensions']; |
|
112
|
|
|
$this->excluded_patterns = $this->default_exclude['patterns']; |
|
113
|
|
|
$this->exclude_hidden = $this->default_exclude['hidden']; |
|
114
|
|
|
|
|
115
|
|
|
return $this; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Check if the config file has any missed attribute, and if any attribute |
|
120
|
|
|
* is missed will be overridden by a default attribute defined in this class. |
|
121
|
|
|
* |
|
122
|
|
|
* @param $configurations |
|
123
|
|
|
*/ |
|
124
|
|
|
private function parseAndFillConfiguration($configurations) |
|
125
|
|
|
{ |
|
126
|
|
|
$this->default_include = isset($configurations['include']) ? |
|
127
|
|
|
array_merge($this->default_include, $configurations['include']) : $this->default_include; |
|
128
|
|
|
|
|
129
|
|
|
$this->default_exclude = isset($configurations['exclude']) ? |
|
130
|
|
|
array_merge($this->default_exclude, $configurations['exclude']) : $this->default_exclude; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @return array |
|
135
|
|
|
*/ |
|
136
|
|
|
public function getIncludedDirectories() |
|
137
|
|
|
{ |
|
138
|
|
|
return $this->included_directories; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @return array |
|
143
|
|
|
*/ |
|
144
|
|
|
public function getIncludedExtensions() |
|
145
|
|
|
{ |
|
146
|
|
|
return $this->included_extensions; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* @return array |
|
151
|
|
|
*/ |
|
152
|
|
|
public function getIncludedPatterns() |
|
153
|
|
|
{ |
|
154
|
|
|
return $this->included_patterns; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* @return array |
|
159
|
|
|
*/ |
|
160
|
|
|
public function getExcludedDirectories() |
|
161
|
|
|
{ |
|
162
|
|
|
return $this->excluded_directories; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* @return array |
|
167
|
|
|
*/ |
|
168
|
|
|
public function getExcludedFiles() |
|
169
|
|
|
{ |
|
170
|
|
|
return $this->excluded_files; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* @return array |
|
175
|
|
|
*/ |
|
176
|
|
|
public function getExcludedExtensions() |
|
177
|
|
|
{ |
|
178
|
|
|
return $this->excluded_extensions; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* @return array |
|
183
|
|
|
*/ |
|
184
|
|
|
public function getExcludedPatterns() |
|
185
|
|
|
{ |
|
186
|
|
|
return $this->excluded_patterns; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* @return Collection |
|
191
|
|
|
*/ |
|
192
|
|
|
public function getAssets() |
|
193
|
|
|
{ |
|
194
|
|
|
return $this->assets; |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* @param mixed $assets |
|
199
|
|
|
*/ |
|
200
|
|
|
public function setAssets($assets) |
|
201
|
|
|
{ |
|
202
|
|
|
$this->assets = $assets; |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* @return mixed |
|
207
|
|
|
*/ |
|
208
|
|
|
public function getExcludeHidden() |
|
209
|
|
|
{ |
|
210
|
|
|
return $this->exclude_hidden; |
|
211
|
|
|
} |
|
212
|
|
|
} |
|
213
|
|
|
|