1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File.php |
5
|
|
|
* |
6
|
|
|
* An uploaded file. |
7
|
|
|
* |
8
|
|
|
* @package jaxon-core |
9
|
|
|
* @author Thierry Feuzeu <[email protected]> |
10
|
|
|
* @copyright 2017 Thierry Feuzeu <[email protected]> |
11
|
|
|
* @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License |
12
|
|
|
* @link https://github.com/jaxon-php/jaxon-core |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Jaxon\Upload\Manager; |
16
|
|
|
|
17
|
|
|
use Jaxon\Request\Upload\FileInterface; |
|
|
|
|
18
|
|
|
use League\Flysystem\Filesystem; |
19
|
|
|
use Nyholm\Psr7\UploadedFile; |
20
|
|
|
|
21
|
|
|
use function pathinfo; |
22
|
|
|
|
23
|
|
|
class File implements FileInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* The uploaded file type |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $sType; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* The uploaded file name, without the extension and sanitized |
34
|
|
|
* |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
protected $sName; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* The uploaded file name, with the extension |
41
|
|
|
* |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
protected $sFilename; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* The uploaded file path |
48
|
|
|
* |
49
|
|
|
* @var string |
50
|
|
|
*/ |
51
|
|
|
protected $sPath; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* The uploaded file size |
55
|
|
|
* |
56
|
|
|
* @var int |
57
|
|
|
*/ |
58
|
|
|
protected $nSize; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* The uploaded file extension |
62
|
|
|
* |
63
|
|
|
* @var string |
64
|
|
|
*/ |
65
|
|
|
protected $sExtension; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* The filesystem where the file is stored |
69
|
|
|
* |
70
|
|
|
* @var Filesystem |
71
|
|
|
*/ |
72
|
|
|
protected $xFilesystem; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Create an instance of this class using data from an uploaded file. |
76
|
|
|
* |
77
|
|
|
* @param Filesystem $xFilesystem |
78
|
|
|
* @param string $sUploadDir |
79
|
|
|
* @param UploadedFile $xHttpFile |
80
|
|
|
* |
81
|
|
|
* @return File |
82
|
|
|
*/ |
83
|
|
|
public static function fromHttpFile(Filesystem $xFilesystem, string $sUploadDir, UploadedFile $xHttpFile): File |
84
|
|
|
{ |
85
|
|
|
$xFile = new File(); |
86
|
|
|
$xFile->xFilesystem = $xFilesystem; |
87
|
|
|
$xFile->sType = $xHttpFile->getClientMediaType(); |
88
|
|
|
$xFile->sFilename = $xHttpFile->getClientFilename(); |
89
|
|
|
$xFile->sExtension = pathinfo($xFile->sFilename, PATHINFO_EXTENSION); |
|
|
|
|
90
|
|
|
$xFile->nSize = $xHttpFile->getSize(); |
91
|
|
|
$xFile->sPath = $sUploadDir . $xFile->sName . '.' . $xFile->sExtension; |
|
|
|
|
92
|
|
|
return $xFile; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Create an instance of this class using data from a temp file |
97
|
|
|
* |
98
|
|
|
* @param Filesystem $xFilesystem |
99
|
|
|
* @param array $aFile The uploaded file data |
100
|
|
|
* |
101
|
|
|
* @return File |
102
|
|
|
*/ |
103
|
|
|
public static function fromTempFile(Filesystem $xFilesystem, array $aFile): File |
104
|
|
|
{ |
105
|
|
|
$xFile = new File(); |
106
|
|
|
$xFile->xFilesystem = $xFilesystem; |
107
|
|
|
$xFile->sType = $aFile['type']; |
108
|
|
|
$xFile->sName = $aFile['name']; |
109
|
|
|
$xFile->sFilename = $aFile['filename']; |
110
|
|
|
$xFile->sExtension = $aFile['extension']; |
111
|
|
|
$xFile->nSize = $aFile['size']; |
112
|
|
|
$xFile->sPath = $aFile['path']; |
113
|
|
|
return $xFile; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Convert the File instance to array. |
118
|
|
|
* |
119
|
|
|
* @return array<string,string> |
120
|
|
|
*/ |
121
|
|
|
public function toTempData(): array |
122
|
|
|
{ |
123
|
|
|
return [ |
124
|
|
|
'type' => $this->sType, |
125
|
|
|
'name' => $this->sName, |
126
|
|
|
'filename' => $this->sFilename, |
127
|
|
|
'extension' => $this->sExtension, |
128
|
|
|
'size' => $this->nSize, |
129
|
|
|
'path' => $this->sPath, |
130
|
|
|
]; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @param string $sName |
135
|
|
|
*/ |
136
|
|
|
public function setName(string $sName): void |
137
|
|
|
{ |
138
|
|
|
$this->sName = $sName; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Get the filesystem where the file is stored |
143
|
|
|
* |
144
|
|
|
* @return Filesystem |
145
|
|
|
*/ |
146
|
|
|
public function filesystem(): Filesystem |
147
|
|
|
{ |
148
|
|
|
return $this->xFilesystem; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Get the uploaded file type |
153
|
|
|
* |
154
|
|
|
* @return string |
155
|
|
|
*/ |
156
|
|
|
public function type(): string |
157
|
|
|
{ |
158
|
|
|
return $this->sType; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Get the uploaded file name, without the extension and slugified |
163
|
|
|
* |
164
|
|
|
* @return string |
165
|
|
|
*/ |
166
|
|
|
public function name(): string |
167
|
|
|
{ |
168
|
|
|
return $this->sName; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Get the uploaded file name, with the extension |
173
|
|
|
* |
174
|
|
|
* @return string |
175
|
|
|
*/ |
176
|
|
|
public function filename(): string |
177
|
|
|
{ |
178
|
|
|
return $this->sFilename; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Get the uploaded file path |
183
|
|
|
* |
184
|
|
|
* @return string |
185
|
|
|
*/ |
186
|
|
|
public function path(): string |
187
|
|
|
{ |
188
|
|
|
return $this->sPath; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Get the uploaded file size |
193
|
|
|
* |
194
|
|
|
* @return int |
195
|
|
|
*/ |
196
|
|
|
public function size(): int |
197
|
|
|
{ |
198
|
|
|
return $this->nSize; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* Get the uploaded file extension |
203
|
|
|
* |
204
|
|
|
* @return string |
205
|
|
|
*/ |
206
|
|
|
public function extension(): string |
207
|
|
|
{ |
208
|
|
|
return $this->sExtension; |
209
|
|
|
} |
210
|
|
|
} |
211
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths