@@ -73,41 +73,46 @@ public function prepareRequest(RequestOptions $requestOptions): RequestInterface
7373 $ request = $ this ->requestFactory ->createRequest ('POST ' , $ uri );
7474
7575 preg_match_all ('~\{([a-zA-Z\d]+):([a-zA-Z\d ]+(\(.+\))?)}~ ' , $ requestOptions ->sql , $ matches );
76- if ($ matches === []) {
76+ if ($ matches[ 0 ] === []) {
7777 $ body = $ this ->streamFactory ->createStream ($ requestOptions ->sql );
78- } else {
79- $ typeToParam = array_reduce (
80- array_keys ($ matches [1 ]),
81- static function (array $ acc , string |int $ k ) use ($ matches ) {
82- $ acc [$ matches [1 ][$ k ]] = Type::fromString ($ matches [2 ][$ k ]);
83-
84- return $ acc ;
85- },
86- [],
87- );
88-
89- $ streamElements = [['name ' => 'query ' , 'contents ' => $ requestOptions ->sql ]];
90- foreach ($ requestOptions ->params as $ name => $ value ) {
91- $ type = $ typeToParam [$ name ] ?? null ;
92- if ($ type === null ) {
93- continue ;
94- }
95-
96- $ streamElements [] = [
97- 'name ' => 'param_ ' . $ name ,
98- 'contents ' => $ this ->paramValueConverterRegistry ->get ($ type )($ value , $ type , false ),
99- ];
100- }
101-
10278 try {
103- $ body = new MultipartStream ($ streamElements );
104- $ request = $ request ->withBody ($ body )
105- ->withHeader ('Content-Type ' , 'multipart/form-data; boundary= ' . $ body ->getBoundary ());
79+ return $ request ->withBody ($ body );
10680 } catch (InvalidArgumentException ) {
10781 absurd ();
10882 }
10983 }
11084
85+ $ typeToParam = array_reduce (
86+ array_keys ($ matches [1 ]),
87+ static function (array $ acc , string |int $ k ) use ($ matches ) {
88+ $ acc [$ matches [1 ][$ k ]] = Type::fromString ($ matches [2 ][$ k ]);
89+
90+ return $ acc ;
91+ },
92+ [],
93+ );
94+
95+ $ streamElements = [['name ' => 'query ' , 'contents ' => $ requestOptions ->sql ]];
96+ foreach ($ requestOptions ->params as $ name => $ value ) {
97+ $ type = $ typeToParam [$ name ] ?? null ;
98+ if ($ type === null ) {
99+ continue ;
100+ }
101+
102+ $ streamElements [] = [
103+ 'name ' => 'param_ ' . $ name ,
104+ 'contents ' => $ this ->paramValueConverterRegistry ->get ($ type )($ value , $ type , false ),
105+ ];
106+ }
107+
108+ try {
109+ $ body = new MultipartStream ($ streamElements );
110+ $ request = $ request ->withBody ($ body )
111+ ->withHeader ('Content-Type ' , 'multipart/form-data; boundary= ' . $ body ->getBoundary ());
112+ } catch (InvalidArgumentException ) {
113+ absurd ();
114+ }
115+
111116 return $ request ;
112117 }
113118}
0 commit comments