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 1414 "php" : " >=8.1" ,
1515 "ext-dom" : " *" ,
1616 "ext-curl" : " *" ,
17+ "ext-fileinfo" : " *" ,
1718 "phpgt/input" : " ^1.2" ,
1819 "phpgt/typesafegetter" : " ^1.3" ,
1920 "phpgt/promise" : " ^2.2" ,
Original file line number Diff line number Diff line change 11<?php
22namespace Gt \Http ;
33
4+ use SplFileObject ;
5+
46class File extends Blob {
57 /**
68 * @param array<ArrayBuffer|Blob|string> $bits
79 * @param string $name
810 * @param array<string, string> $options
911 */
1012 public function __construct (
11- array $ bits ,
13+ SplFileObject | array $ bits ,
1214 string $ name ,
1315 array $ options = [],
1416 ) {
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+
1527 parent ::__construct ($ bits , $ options );
1628 $ this ->name = $ name ;
1729 }
Original file line number Diff line number Diff line change 66use DOMXPath ;
77use Generator ;
88use Gt \TypeSafeGetter \NullableTypeSafeGetter ;
9+ use SplFileObject ;
910use Stringable ;
1011use Countable ;
1112use Iterator ;
@@ -104,17 +105,19 @@ public function getBlob(string $name):?Blob {
104105 */
105106 public function append (
106107 string $ name ,
107- Blob |File |string $ value ,
108+ Blob |File |SplFileObject | string $ value ,
108109 string $ filename = null
109110 ):void {
111+ $ value = $ this ->normaliseFileValue ($ value );
110112 $ this ->appendAnyValue ($ name , $ value , $ filename );
111113 }
112114
113115 public function set (
114116 string $ name ,
115- Blob |File |string $ value ,
117+ Blob |File |SplFileObject | string $ value ,
116118 ?string $ filename = null ,
117119 ):void {
120+ $ value = $ this ->normaliseFileValue ($ value );
118121 $ this ->setAnyValue ($ name , $ value , $ filename );
119122 }
120123
@@ -183,4 +186,14 @@ private function getValueFromSelect(DOMElement $select):string {
183186
184187 return "" ;
185188 }
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+ }
186199}
Original file line number Diff line number Diff line change 22namespace Gt \Http ;
33
44use Generator ;
5+ use SplFileObject ;
56
67/** @SuppressWarnings("TooManyPublicMethods") */
78abstract class KeyValuePairStore {
You can’t perform that action at this time.
0 commit comments