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
|
11 |
|
public function __construct() |
32
|
|
|
{ |
33
|
11 |
|
} |
34
|
|
|
|
35
|
2 |
|
public function __toString() |
36
|
|
|
{ |
37
|
2 |
|
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
|
3 |
|
public function getFilename() |
56
|
|
|
{ |
57
|
3 |
|
return $this->filename; |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Returns the filepath property. |
62
|
|
|
* |
63
|
|
|
* @return string |
64
|
|
|
*/ |
65
|
1 |
|
public function getFilepath() |
66
|
|
|
{ |
67
|
1 |
|
return $this->filepath; |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Returns the extension property. |
72
|
|
|
* |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
3 |
|
public function getExtension() |
76
|
|
|
{ |
77
|
3 |
|
return $this->extension; |
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Returns the pathname property. |
82
|
|
|
* |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
3 |
|
public function getPathname() |
86
|
|
|
{ |
87
|
3 |
|
return $this->pathname; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Returns the mimeType property. |
92
|
|
|
* |
93
|
|
|
* @return string |
94
|
|
|
*/ |
95
|
3 |
|
public function getMimeType() |
96
|
|
|
{ |
97
|
3 |
|
return $this->mimeType; |
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Returns the clientOriginalName property. |
102
|
|
|
* |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
1 |
|
public function getClientOriginalName() |
106
|
|
|
{ |
107
|
1 |
|
return $this->clientOriginalName; |
|
|
|
|
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Returns the clientOriginalExtension property. |
112
|
|
|
* |
113
|
|
|
* @return string |
114
|
|
|
*/ |
115
|
1 |
|
public function getClientOriginalExtension() |
116
|
|
|
{ |
117
|
1 |
|
return $this->clientOriginalExtension; |
|
|
|
|
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Returns the clientMimeType property. |
122
|
|
|
* |
123
|
|
|
* @return string |
124
|
|
|
*/ |
125
|
1 |
|
public function getClientMimeType() |
126
|
|
|
{ |
127
|
1 |
|
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
|
11 |
|
public function setFilename($value) |
149
|
|
|
{ |
150
|
11 |
|
$this->filename = $value; |
151
|
11 |
|
return $this; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Sets the filepath property. |
156
|
|
|
* |
157
|
|
|
* @param string $value |
158
|
|
|
* @return self |
159
|
|
|
*/ |
160
|
3 |
|
public function setFilepath($value) |
161
|
|
|
{ |
162
|
3 |
|
$this->filepath = $value; |
163
|
3 |
|
return $this; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Sets the extension property. |
168
|
|
|
* |
169
|
|
|
* @param string $value |
170
|
|
|
* @return self |
171
|
|
|
*/ |
172
|
11 |
|
public function setExtension($value) |
173
|
|
|
{ |
174
|
11 |
|
$this->extension = $value; |
175
|
11 |
|
return $this; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Sets the pathname property. |
180
|
|
|
* |
181
|
|
|
* @param string $value |
182
|
|
|
* @return self |
183
|
|
|
*/ |
184
|
11 |
|
public function setPathname($value) |
185
|
|
|
{ |
186
|
11 |
|
$this->pathname = $value; |
187
|
11 |
|
return $this; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Sets the mimeType property. |
192
|
|
|
* |
193
|
|
|
* @param string $value |
194
|
|
|
* @return self |
195
|
|
|
*/ |
196
|
11 |
|
public function setMimeType($value) |
197
|
|
|
{ |
198
|
11 |
|
$this->mimeType = $value; |
|
|
|
|
199
|
11 |
|
return $this; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Sets the clientOriginalName property. |
204
|
|
|
* |
205
|
|
|
* @param string $value |
206
|
|
|
* @return self |
207
|
|
|
*/ |
208
|
11 |
|
public function setClientOriginalName($value) |
209
|
|
|
{ |
210
|
11 |
|
$this->clientOriginalName = $value; |
|
|
|
|
211
|
11 |
|
return $this; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* Sets the clientOriginalExtension property. |
216
|
|
|
* |
217
|
|
|
* @param string $value |
218
|
|
|
* @return self |
219
|
|
|
*/ |
220
|
11 |
|
public function setClientOriginalExtension($value) |
221
|
|
|
{ |
222
|
11 |
|
$this->clientOriginalExtension = $value; |
|
|
|
|
223
|
11 |
|
return $this; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* Sets the clientMimeType property. |
228
|
|
|
* |
229
|
|
|
* @param string $value |
230
|
|
|
* @return self |
231
|
|
|
*/ |
232
|
1 |
|
public function setClientMimeType($value) |
233
|
|
|
{ |
234
|
1 |
|
$this->clientMimeType = $value; |
|
|
|
|
235
|
1 |
|
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: