diff --git a/src/Service/CallService.php b/src/Service/CallService.php index 2b971cce..ceaf1e3d 100644 --- a/src/Service/CallService.php +++ b/src/Service/CallService.php @@ -348,7 +348,7 @@ public function call( 'Request failed with error '.$exception, [ 'sourceCall' => $this->sourceCallLogData(['method' => $method, 'url' => $url, 'response' => $response ?? null], $config), - ] + ], ); if (empty($response) === false) { @@ -502,6 +502,8 @@ private function handleEndpointConfigOut(array $config, array $endpointConfigOut $body = $this->mappingService->mapping($mapping, $body); $config[$configKey] = \Safe\json_encode($body); + unset($config['headers']['Content-Type'], $config['headers']['Accept'], $config['headers']['accept'], $config['headers']['content-type']); + $config['headers']['content-type'] = 'application/json'; } catch (Exception | LoaderError | SyntaxError $exception) { $this->callLogger->error("Could not map with mapping {$endpointConfigOut[$configKey]['mapping']} while handling $configKey EndpointConfigOut for a Source. ".$exception->getMessage()); diff --git a/src/Service/EndpointService.php b/src/Service/EndpointService.php index a2906beb..80465efe 100644 --- a/src/Service/EndpointService.php +++ b/src/Service/EndpointService.php @@ -551,14 +551,22 @@ private function getNormalPath(array $parameters): array $this->logger->debug('EndpointService->getNormalPath(): '.$exception->getMessage()); // Todo: When an id is not given the last element of the path array should be removed to ensure the arrays are of the same length. - array_pop($path); - $combinedArray = array_combine($path, explode('/', $pathRaw)); + if (count(explode('/', $pathRaw)) > count($path)) { + $combinedArray = array_combine($path, explode('/', $pathRaw, count($path))); + } else { + array_pop($path); + $combinedArray = array_combine($path, explode('/', $pathRaw)); + } } if ($combinedArray === false) { - // Todo: When an id is not given the last element of the path array should be removed to ensure the arrays are of the same length. - array_pop($path); - $combinedArray = array_combine($path, explode('/', $pathRaw)); + // When an id is not given the last element of the path array should be removed to ensure the arrays are of the same length. + if (count(explode('/', $pathRaw)) > count($path)) { + $combinedArray = array_combine($path, explode('/', $pathRaw, count($path))); + } else { + array_pop($path); + $combinedArray = array_combine($path, explode('/', $pathRaw)); + } } if ($combinedArray === false) { diff --git a/src/Twig/CallExtension.php b/src/Twig/CallExtension.php new file mode 100644 index 00000000..3bfdc0e8 --- /dev/null +++ b/src/Twig/CallExtension.php @@ -0,0 +1,17 @@ +resourceService->getSource($sourceId, 'common-gateway/zgw-to-zds-bundle'); + + $response = $this->callService->call($source, $endpoint, $method, $configuration); + return $this->callService->decodeResponse($source, $response); + + }//end call() +}//end class