1111use Psr \Http \Message \StreamInterface ;
1212use Gt \Input \Trigger \Trigger ;
1313use Gt \Input \InputData \InputData ;
14+ use Gt \Input \InputData \Datum \StreamNotAvailableException ;
1415use Gt \Input \InputData \Datum \InputDatum ;
1516use Gt \Input \InputData \KeyValueArrayAccess ;
1617use Gt \Input \InputData \KeyValueCountable ;
@@ -38,6 +39,7 @@ class Input implements ArrayAccess, Countable, Iterator {
3839 const DATA_COMBINED = "combined " ;
3940
4041 protected BodyStream $ bodyStream ;
42+ protected string $ requestMethod ;
4143 protected QueryStringInputData $ queryStringParameters ;
4244 protected BodyInputData $ bodyParameters ;
4345
@@ -52,8 +54,12 @@ public function __construct(
5254 array $ post = [],
5355 array $ files = [],
5456 string $ bodyPath = "php://input " ,
57+ ?string $ requestMethod = null ,
5558 ) {
5659 $ this ->bodyStream = new BodyStream ($ bodyPath );
60+ $ this ->requestMethod = strtoupper (
61+ $ requestMethod ?? ($ _SERVER ["REQUEST_METHOD " ] ?? "GET " )
62+ );
5763
5864 $ this ->queryStringParameters = new QueryStringInputData ($ get );
5965 $ this ->bodyParameters = new BodyInputData ($ post );
@@ -73,6 +79,19 @@ public function getStream():StreamInterface {
7379 return $ this ->bodyStream ;
7480 }
7581
82+ /**
83+ * Returns a streamable PUT file upload body.
84+ */
85+ public function getPutFileStream ():BodyStream {
86+ if ($ this ->requestMethod !== "PUT " ) {
87+ throw new StreamNotAvailableException (
88+ "PUT file stream is only available for PUT requests. "
89+ );
90+ }
91+
92+ return $ this ->bodyStream ;
93+ }
94+
7695 public function add (string $ key , InputDatum $ datum , string $ method ):void {
7796 switch ($ method ) {
7897 case self ::DATA_QUERYSTRING :
0 commit comments