Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Service/CallService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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());
Expand Down
18 changes: 13 additions & 5 deletions src/Service/EndpointService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 17 additions & 0 deletions src/Twig/CallExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace CommonGateway\CoreBundle\Twig;

use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class CallExtension extends AbstractExtension
{
public function getFunctions()
{
return [
new TwigFunction('call', [CallRuntime::class, 'call']),
];

}//end getFunctions()
}//end class
35 changes: 35 additions & 0 deletions src/Twig/CallRuntime.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace CommonGateway\CoreBundle\Twig;

use Adbar\Dot;
use CommonGateway\CoreBundle\Service\CallService;
use CommonGateway\CoreBundle\Service\GatewayResourceService;
use Doctrine\ORM\EntityManagerInterface;
use Twig\Extension\RuntimeExtensionInterface;

class CallRuntime implements RuntimeExtensionInterface
{
public function __construct(
private readonly CallService $callService,
private readonly GatewayResourceService $resourceService
) {

}//end __construct()

/**
* Call source of given id or reference
*
* @param array $array The array to turn into a dot array.
*
* @return array The dot aray.
*/
public function call(string $sourceId, string $endpoint, string $method = 'GET', array $configuration = []): array
{
$source = $this->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