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,10 @@ public function __construct(
5254 array $ post = [],
5355 array $ files = [],
5456 string $ bodyPath = "php://input " ,
57+ ?string $ requestMethod = "GET " ,
5558 ) {
5659 $ this ->bodyStream = new BodyStream ($ bodyPath );
60+ $ this ->requestMethod = strtoupper ($ requestMethod );
5761
5862 $ this ->queryStringParameters = new QueryStringInputData ($ get );
5963 $ this ->bodyParameters = new BodyInputData ($ post );
@@ -73,6 +77,19 @@ public function getStream():StreamInterface {
7377 return $ this ->bodyStream ;
7478 }
7579
80+ /**
81+ * Returns a streamable PUT file upload body.
82+ */
83+ public function getPutFileStream ():BodyStream {
84+ if ($ this ->requestMethod !== "PUT " ) {
85+ throw new StreamNotAvailableException (
86+ "PUT file stream is only available for PUT requests. "
87+ );
88+ }
89+
90+ return $ this ->bodyStream ;
91+ }
92+
7693 public function add (string $ key , InputDatum $ datum , string $ method ):void {
7794 switch ($ method ) {
7895 case self ::DATA_QUERYSTRING :
0 commit comments