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
66 changes: 33 additions & 33 deletions src/Service/CallService.php
Original file line number Diff line number Diff line change
Expand Up @@ -744,17 +744,17 @@ public function decodeResponse(

// This if is statement prevents binary code from being used a string.
if (in_array(
$contentType,
[
'application/pdf',
'application/pdf; charset=utf-8',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document; charset=utf-8',
'application/msword',
'image/jpeg',
'image/png',
]
) === false
$contentType,
[
'application/pdf',
'application/pdf; charset=utf-8',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document; charset=utf-8',
'application/msword',
'image/jpeg',
'image/png',
]
) === false
) {
$this->callLogger->debug('Response content: '.$responseBody);
}
Expand All @@ -768,28 +768,28 @@ public function decodeResponse(
}

switch ($contentType) {
case 'text/plain':
return $responseBody;
case 'text/yaml':
case 'text/x-yaml':
case 'text/yaml; charset=utf-8':
return $yamlEncoder->decode($responseBody, 'yaml');
case 'text/xml':
case 'text/xml; charset=utf-8':
case 'application/pdf':
case 'application/pdf; charset=utf-8':
case 'application/msword':
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document; charset=utf-8':
case 'image/jpeg':
case 'image/png':
$this->callLogger->debug('Response content: binary code..');
return base64_encode($responseBody);
case 'application/xml':
case 'application/xml; charset=utf-8':
return $xmlEncoder->decode($responseBody, 'xml');
case 'application/json':
case 'application/json; charset=utf-8':
case 'text/plain':
return $responseBody;
case 'text/yaml':
case 'text/x-yaml':
case 'text/yaml; charset=utf-8':
return $yamlEncoder->decode($responseBody, 'yaml');
case 'text/xml':
case 'text/xml; charset=utf-8':
case 'application/pdf':
case 'application/pdf; charset=utf-8':
case 'application/msword':
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document; charset=utf-8':
case 'image/jpeg':
case 'image/png':
$this->callLogger->debug('Response content: binary code..');
return base64_encode($responseBody);
case 'application/xml':
case 'application/xml; charset=utf-8':
return $xmlEncoder->decode($responseBody, 'xml');
case 'application/json':
case 'application/json; charset=utf-8':
default:
$result = json_decode($responseBody, true);
}//end switch
Expand Down
109 changes: 54 additions & 55 deletions src/Service/EndpointService.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,39 +220,39 @@ private function determineAcceptType(string $acceptHeader): ?string
// Determine the accept type.
$this->logger->debug('Determine accept type from accept header');
switch ($acceptHeader) {
case 'application/pdf':
return 'pdf';
case 'application/json':
return 'json';
case 'application/json+hal':
case 'application/hal+json':
return 'jsonhal';
case 'application/json+ld':
case 'application/ld+json':
return 'jsonld';
case 'application/json+fromio':
case 'application/formio+json':
return 'formio';
case 'application/json+schema':
case 'application/schema+json':
return 'schema';
case 'application/json+graphql':
case 'application/graphql+json':
return 'graphql';
case 'text/xml':
case 'application/xml':
return 'xml';
case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
return 'xlsx';
case 'text/csv':
return 'csv';
case 'text/html':
return 'html';
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
return 'docx';
case 'application/pdf':
return 'pdf';
case 'application/json':
return 'json';
case 'application/json+hal':
case 'application/hal+json':
return 'jsonhal';
case 'application/json+ld':
case 'application/ld+json':
return 'jsonld';
case 'application/json+fromio':
case 'application/formio+json':
return 'formio';
case 'application/json+schema':
case 'application/schema+json':
return 'schema';
case 'application/json+graphql':
case 'application/graphql+json':
return 'graphql';
case 'text/xml':
case 'application/xml':
return 'xml';
case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
return 'xlsx';
case 'text/csv':
return 'csv';
case 'text/html':
return 'html';
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
return 'docx';
break;
case 'application/json+aggregations':
return 'aggregations';
case 'application/json+aggregations':
return 'aggregations';
}//end switch

return null;
Expand Down Expand Up @@ -302,8 +302,8 @@ public function getAcceptType(): string
if (count($pathparts) >= 2) {
$extension = end($pathparts);
switch ($extension) {
case 'pdf':
return 'pdf';
case 'pdf':
return 'pdf';
}//end switch
}

Expand Down Expand Up @@ -334,14 +334,14 @@ public function decodeBody(): ?array

// Decode the body.
switch ($contentType) {
case 'text/xml':
case 'application/xml':
case 'xml':
$xmlEncoder = new XmlEncoder(['load_options' => LIBXML_PARSEHUGE]);

return $xmlEncoder->decode($this->request->getContent(), 'xml');
default:
return json_decode($this->request->getContent(), true);
case 'text/xml':
case 'application/xml':
case 'xml':
$xmlEncoder = new XmlEncoder(['load_options' => LIBXML_PARSEHUGE]);

return $xmlEncoder->decode($this->request->getContent(), 'xml');
default:
return json_decode($this->request->getContent(), true);
}//end switch

}//end decodeBody()
Expand Down Expand Up @@ -426,10 +426,10 @@ private function getPutData(): array

$filename = null;
if (preg_match(
'/^(.+); *name="([^"]+)"(; *filename="([^"]+)")?/',
$headers['content-disposition'],
$matches
) === false
'/^(.+); *name="([^"]+)"(; *filename="([^"]+)")?/',
$headers['content-disposition'],
$matches
) === false
) {
preg_match(
'/^(.+); *name=([-+.\w]+)(; *filename=([-+.\w]+))?/',
Expand All @@ -444,14 +444,14 @@ private function getPutData(): array
// Handle your fields here.
switch ($name) {
// This is a file upload.
case 'userfile':
file_put_contents($filename, $body);
break;
case 'userfile':
file_put_contents($filename, $body);
break;

// Default for all other files is to populate $data.
default:
$data[$name] = substr($body, 0, (strlen($body) - 2));
break;
default:
$data[$name] = substr($body, 0, (strlen($body) - 2));
break;
}
}//end foreach

Expand Down Expand Up @@ -551,8 +551,7 @@ 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.

if(count(explode('/', $pathRaw)) > count($path)) {
if (count(explode('/', $pathRaw)) > count($path)) {
$combinedArray = array_combine($path, explode('/', $pathRaw, count($path)));
} else {
array_pop($path);
Expand All @@ -562,7 +561,7 @@ private function getNormalPath(array $parameters): array

if ($combinedArray === false) {
// 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)) {
if (count(explode('/', $pathRaw)) > count($path)) {
$combinedArray = array_combine($path, explode('/', $pathRaw, count($path)));
} else {
array_pop($path);
Expand Down
4 changes: 4 additions & 0 deletions src/Service/RequestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ private function unserializeData(string $content, string $contentType, ?string &
$namespaces = array_combine(
array_map(
function ($key) {
if ($key === '') {
return '@xmlns';
}

return '@xmlns:'.$key;
},
array_keys($xml->getDocNamespaces(true))
Expand Down
4 changes: 0 additions & 4 deletions src/Twig/CallExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@

class CallExtension extends AbstractExtension
{


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

}//end getFunctions()


}//end class
7 changes: 1 addition & 6 deletions src/Twig/CallRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,26 @@

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
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