diff --git a/src/Client/Http/RequestFactory.php b/src/Client/Http/RequestFactory.php index 215b670..863ce5f 100644 --- a/src/Client/Http/RequestFactory.php +++ b/src/Client/Http/RequestFactory.php @@ -73,41 +73,46 @@ public function prepareRequest(RequestOptions $requestOptions): RequestInterface $request = $this->requestFactory->createRequest('POST', $uri); preg_match_all('~\{([a-zA-Z\d]+):([a-zA-Z\d ]+(\(.+\))?)}~', $requestOptions->sql, $matches); - if ($matches === []) { + if ($matches[0] === []) { $body = $this->streamFactory->createStream($requestOptions->sql); - } else { - $typeToParam = array_reduce( - array_keys($matches[1]), - static function (array $acc, string|int $k) use ($matches) { - $acc[$matches[1][$k]] = Type::fromString($matches[2][$k]); - - return $acc; - }, - [], - ); - - $streamElements = [['name' => 'query', 'contents' => $requestOptions->sql]]; - foreach ($requestOptions->params as $name => $value) { - $type = $typeToParam[$name] ?? null; - if ($type === null) { - continue; - } - - $streamElements[] = [ - 'name' => 'param_' . $name, - 'contents' => $this->paramValueConverterRegistry->get($type)($value, $type, false), - ]; - } - try { - $body = new MultipartStream($streamElements); - $request = $request->withBody($body) - ->withHeader('Content-Type', 'multipart/form-data; boundary=' . $body->getBoundary()); + return $request->withBody($body); } catch (InvalidArgumentException) { absurd(); } } + $typeToParam = array_reduce( + array_keys($matches[1]), + static function (array $acc, string|int $k) use ($matches) { + $acc[$matches[1][$k]] = Type::fromString($matches[2][$k]); + + return $acc; + }, + [], + ); + + $streamElements = [['name' => 'query', 'contents' => $requestOptions->sql]]; + foreach ($requestOptions->params as $name => $value) { + $type = $typeToParam[$name] ?? null; + if ($type === null) { + continue; + } + + $streamElements[] = [ + 'name' => 'param_' . $name, + 'contents' => $this->paramValueConverterRegistry->get($type)($value, $type, false), + ]; + } + + try { + $body = new MultipartStream($streamElements); + $request = $request->withBody($body) + ->withHeader('Content-Type', 'multipart/form-data; boundary=' . $body->getBoundary()); + } catch (InvalidArgumentException) { + absurd(); + } + return $request; } }