File tree Expand file tree Collapse file tree 4 files changed +30
-3
lines changed Expand file tree Collapse file tree 4 files changed +30
-3
lines changed Original file line number Diff line number Diff line change 14
14
"php" : " >=8.1" ,
15
15
"ext-dom" : " *" ,
16
16
"ext-curl" : " *" ,
17
+ "ext-fileinfo" : " *" ,
17
18
"phpgt/input" : " ^1.2" ,
18
19
"phpgt/typesafegetter" : " ^1.3" ,
19
20
"phpgt/promise" : " ^2.2" ,
Original file line number Diff line number Diff line change 1
1
<?php
2
2
namespace Gt \Http ;
3
3
4
+ use SplFileObject ;
5
+
4
6
class File extends Blob {
5
7
/**
6
8
* @param array<ArrayBuffer|Blob|string> $bits
7
9
* @param string $name
8
10
* @param array<string, string> $options
9
11
*/
10
12
public function __construct (
11
- array $ bits ,
13
+ SplFileObject | array $ bits ,
12
14
string $ name ,
13
15
array $ options = [],
14
16
) {
17
+ if ($ bits instanceof SplFileObject) {
18
+ $ file = $ bits ;
19
+ $ bits = [];
20
+ while (!$ file ->eof ()) {
21
+ array_push ($ bits , $ file ->fread (1024 ));
22
+ }
23
+ }
24
+
25
+ /** @var array<ArrayBuffer|Blob|string> $bits */
26
+
15
27
parent ::__construct ($ bits , $ options );
16
28
$ this ->name = $ name ;
17
29
}
Original file line number Diff line number Diff line change 6
6
use DOMXPath ;
7
7
use Generator ;
8
8
use Gt \TypeSafeGetter \NullableTypeSafeGetter ;
9
+ use SplFileObject ;
9
10
use Stringable ;
10
11
use Countable ;
11
12
use Iterator ;
@@ -104,17 +105,19 @@ public function getBlob(string $name):?Blob {
104
105
*/
105
106
public function append (
106
107
string $ name ,
107
- Blob |File |string $ value ,
108
+ Blob |File |SplFileObject | string $ value ,
108
109
string $ filename = null
109
110
):void {
111
+ $ value = $ this ->normaliseFileValue ($ value );
110
112
$ this ->appendAnyValue ($ name , $ value , $ filename );
111
113
}
112
114
113
115
public function set (
114
116
string $ name ,
115
- Blob |File |string $ value ,
117
+ Blob |File |SplFileObject | string $ value ,
116
118
?string $ filename = null ,
117
119
):void {
120
+ $ value = $ this ->normaliseFileValue ($ value );
118
121
$ this ->setAnyValue ($ name , $ value , $ filename );
119
122
}
120
123
@@ -183,4 +186,14 @@ private function getValueFromSelect(DOMElement $select):string {
183
186
184
187
return "" ;
185
188
}
189
+
190
+ private function normaliseFileValue (Blob |File |SplFileObject |string $ value ):Blob |File |string {
191
+ if (!$ value instanceof SplFileObject) {
192
+ return $ value ;
193
+ }
194
+
195
+ /** @var SplFileObject $file */
196
+ $ file = $ value ;
197
+ return new File ($ file , $ file ->getFilename ());
198
+ }
186
199
}
Original file line number Diff line number Diff line change 2
2
namespace Gt \Http ;
3
3
4
4
use Generator ;
5
+ use SplFileObject ;
5
6
6
7
/** @SuppressWarnings("TooManyPublicMethods") */
7
8
abstract class KeyValuePairStore {
You can’t perform that action at this time.
0 commit comments