|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the limit0/assets package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Limit Zero, LLC <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Limit0\Assets; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\HttpFoundation\File\UploadedFile; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* An Asset model extends the functionality available in \SplFileInfo and UploadedFile |
|
18
|
|
|
* |
|
19
|
|
|
* @author Josh Worden <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class Asset extends UploadedFile |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var array |
|
25
|
|
|
*/ |
|
26
|
|
|
private $storageMetadata = []; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Override UploadedFile constructor |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct() |
|
32
|
|
|
{ |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function __toString() |
|
36
|
|
|
{ |
|
37
|
|
|
return $this->pathname; |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Returns the filename property. |
|
42
|
|
|
* |
|
43
|
|
|
* @return array |
|
44
|
|
|
*/ |
|
45
|
|
|
public function getStorageMetadata() |
|
46
|
|
|
{ |
|
47
|
|
|
return $this->storageMetadata; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Returns the filename property. |
|
52
|
|
|
* |
|
53
|
|
|
* @return string |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getFilename() |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->filename; |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Returns the filepath property. |
|
62
|
|
|
* |
|
63
|
|
|
* @return string |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getFilepath() |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->filepath; |
|
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Returns the extension property. |
|
72
|
|
|
* |
|
73
|
|
|
* @return string |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getExtension() |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->extension; |
|
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Returns the pathname property. |
|
82
|
|
|
* |
|
83
|
|
|
* @return string |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getPathname() |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->pathname; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Returns the mimeType property. |
|
92
|
|
|
* |
|
93
|
|
|
* @return string |
|
94
|
|
|
*/ |
|
95
|
|
|
public function getMimeType() |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->mimeType; |
|
|
|
|
|
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Returns the clientOriginalName property. |
|
102
|
|
|
* |
|
103
|
|
|
* @return string |
|
104
|
|
|
*/ |
|
105
|
|
|
public function getClientOriginalName() |
|
106
|
|
|
{ |
|
107
|
|
|
return $this->clientOriginalName; |
|
|
|
|
|
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Returns the clientOriginalExtension property. |
|
112
|
|
|
* |
|
113
|
|
|
* @return string |
|
114
|
|
|
*/ |
|
115
|
|
|
public function getClientOriginalExtension() |
|
116
|
|
|
{ |
|
117
|
|
|
return $this->clientOriginalExtension; |
|
|
|
|
|
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Returns the clientMimeType property. |
|
122
|
|
|
* |
|
123
|
|
|
* @return string |
|
124
|
|
|
*/ |
|
125
|
|
|
public function getClientMimeType() |
|
126
|
|
|
{ |
|
127
|
|
|
return $this->clientMimeType; |
|
|
|
|
|
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Returns the filename property. |
|
132
|
|
|
* |
|
133
|
|
|
* @param array $value |
|
134
|
|
|
* @return self |
|
135
|
|
|
*/ |
|
136
|
|
|
public function setStorageMetadata(array $value = []) |
|
137
|
|
|
{ |
|
138
|
|
|
$this->storageMetadata = $value; |
|
139
|
|
|
return $this; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Sets the filename property. |
|
144
|
|
|
* |
|
145
|
|
|
* @param string $value |
|
146
|
|
|
* @return self |
|
147
|
|
|
*/ |
|
148
|
|
|
public function setFilename($value) |
|
149
|
|
|
{ |
|
150
|
|
|
$this->filename = $value; |
|
151
|
|
|
return $this; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* Sets the filepath property. |
|
156
|
|
|
* |
|
157
|
|
|
* @param string $value |
|
158
|
|
|
* @return self |
|
159
|
|
|
*/ |
|
160
|
|
|
public function setFilepath($value) |
|
161
|
|
|
{ |
|
162
|
|
|
$this->filepath = $value; |
|
163
|
|
|
return $this; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* Sets the extension property. |
|
168
|
|
|
* |
|
169
|
|
|
* @param string $value |
|
170
|
|
|
* @return self |
|
171
|
|
|
*/ |
|
172
|
|
|
public function setExtension($value) |
|
173
|
|
|
{ |
|
174
|
|
|
$this->extension = $value; |
|
175
|
|
|
return $this; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* Sets the pathname property. |
|
180
|
|
|
* |
|
181
|
|
|
* @param string $value |
|
182
|
|
|
* @return self |
|
183
|
|
|
*/ |
|
184
|
|
|
public function setPathname($value) |
|
185
|
|
|
{ |
|
186
|
|
|
$this->pathname = $value; |
|
187
|
|
|
return $this; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* Sets the mimeType property. |
|
192
|
|
|
* |
|
193
|
|
|
* @param string $value |
|
194
|
|
|
* @return self |
|
195
|
|
|
*/ |
|
196
|
|
|
public function setMimeType($value) |
|
197
|
|
|
{ |
|
198
|
|
|
$this->mimeType = $value; |
|
|
|
|
|
|
199
|
|
|
return $this; |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* Sets the clientOriginalName property. |
|
204
|
|
|
* |
|
205
|
|
|
* @param string $value |
|
206
|
|
|
* @return self |
|
207
|
|
|
*/ |
|
208
|
|
|
public function setClientOriginalName($value) |
|
209
|
|
|
{ |
|
210
|
|
|
$this->clientOriginalName = $value; |
|
|
|
|
|
|
211
|
|
|
return $this; |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* Sets the clientOriginalExtension property. |
|
216
|
|
|
* |
|
217
|
|
|
* @param string $value |
|
218
|
|
|
* @return self |
|
219
|
|
|
*/ |
|
220
|
|
|
public function setClientOriginalExtension($value) |
|
221
|
|
|
{ |
|
222
|
|
|
$this->clientOriginalExtension = $value; |
|
|
|
|
|
|
223
|
|
|
return $this; |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* Sets the clientMimeType property. |
|
228
|
|
|
* |
|
229
|
|
|
* @param string $value |
|
230
|
|
|
* @return self |
|
231
|
|
|
*/ |
|
232
|
|
|
public function setClientMimeType($value) |
|
233
|
|
|
{ |
|
234
|
|
|
$this->clientMimeType = $value; |
|
|
|
|
|
|
235
|
|
|
return $this; |
|
236
|
|
|
} |
|
237
|
|
|
} |
|
238
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: