From 13c373b132e4433e95d6ff193d7c24c3acbdb836 Mon Sep 17 00:00:00 2001 From: Barry Brands Date: Wed, 15 Feb 2023 16:15:25 +0100 Subject: [PATCH 1/7] getHeaders fix and dot->get added --- Service/CallService.php | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/Service/CallService.php b/Service/CallService.php index 661f80e2..b9fe75ba 100644 --- a/Service/CallService.php +++ b/Service/CallService.php @@ -2,7 +2,7 @@ namespace CommonGateway\CoreBundle\Service; -//use App\Entity\CallLog; +use Adbar\Dot; use App\Entity\Gateway as Source; use Doctrine\ORM\EntityManagerInterface; use GuzzleHttp\Client; @@ -156,6 +156,11 @@ public function call( // $log->setRequestHeaders($config['headers'] ?? null); $url = $source->getLocation().$endpoint; + foreach ($source->getHeaders() as $header) { + if (isset($header['key']) && isset($header['value'])) { + $config['headers'][$header['key']] = $header['value']; + } + } $startTimer = microtime(true); // Lets make the call @@ -294,13 +299,14 @@ private function getAuthentication(Source $source): array * * @TODO: This is based on some assumptions * - * @param Source $source The source to call - * @param string $endpoint The endpoint on the source to call - * @param array $config The additional configuration to call the source + * @param Source $source The source to call + * @param string $endpoint The endpoint on the source to call + * @param array $config The additional configuration to call the source + * @param array $objectsLocation The additional configuration to call the source * * @return array The array of results */ - public function getAllResults(Source $source, string $endpoint = '', array $config = []): array + public function getAllResults(Source $source, string $endpoint = '', array $config = [], ?string $objectsLocation = null): array { $errorCount = 0; $pageCount = 1; @@ -326,12 +332,19 @@ public function getAllResults(Source $source, string $endpoint = '', array $conf } catch (\Exception $exception) { $errorCount++; } - if (isset($decodedResponse['results'])) { - $results = array_merge($decodedResponse['results'], $results); - } elseif (isset($decodedResponse['items'])) { - $results = array_merge($decodedResponse['items'], $results); - } elseif (isset($decodedResponse[0])) { - $results = array_merge($decodedResponse, $results); + + // Get objects through dot notation + if ($objectsLocation) { + $dot = new Dot($decodedResponse); + $results = array_merge($dot->get($objectsLocation), $results); + } else { // else do some assumptions + if (isset($decodedResponse['results'])) { + $results = array_merge($decodedResponse['results'], $results); + } elseif (isset($decodedResponse['items'])) { + $results = array_merge($decodedResponse['items'], $results); + } elseif (isset($decodedResponse[0])) { + $results = array_merge($decodedResponse, $results); + } } } From a9d038cb3c0205e1a367576c56ab82d90ce83fa2 Mon Sep 17 00:00:00 2001 From: GitHub Actions <> Date: Wed, 15 Feb 2023 15:15:49 +0000 Subject: [PATCH 2/7] Update phpdoc --- docs/classes/Service/CallService.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/classes/Service/CallService.md b/docs/classes/Service/CallService.md index 3e3aaa4f..1f1b19a1 100644 --- a/docs/classes/Service/CallService.md +++ b/docs/classes/Service/CallService.md @@ -122,7 +122,7 @@ Decodes a response based on the source it belongs to. **Description** ```php -public getAllResults (\Source $source, string $endpoint, array $config) +public getAllResults (\Source $source, string $endpoint, array $config, array $objectsLocation) ``` Fetches all pages for a source and merges the result arrays to one array. @@ -137,6 +137,8 @@ Fetches all pages for a source and merges the result arrays to one array. : The endpoint on the source to call * `(array) $config` : The additional configuration to call the source +* `(array) $objectsLocation` +: The additional configuration to call the source **Return Values** From d4388972700c994104007f67571c7d90d354e9ef Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Wed, 15 Feb 2023 15:19:44 +0000 Subject: [PATCH 3/7] Apply fixes from StyleCI --- Service/CallService.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Service/CallService.php b/Service/CallService.php index b9fe75ba..a6fd5bc5 100644 --- a/Service/CallService.php +++ b/Service/CallService.php @@ -299,10 +299,10 @@ private function getAuthentication(Source $source): array * * @TODO: This is based on some assumptions * - * @param Source $source The source to call - * @param string $endpoint The endpoint on the source to call - * @param array $config The additional configuration to call the source - * @param array $objectsLocation The additional configuration to call the source + * @param Source $source The source to call + * @param string $endpoint The endpoint on the source to call + * @param array $config The additional configuration to call the source + * @param array $objectsLocation The additional configuration to call the source * * @return array The array of results */ From 6e499db2c6190d6862a2dd3e9b00881b11c79b54 Mon Sep 17 00:00:00 2001 From: Barry Brands Date: Wed, 15 Feb 2023 16:22:32 +0100 Subject: [PATCH 4/7] undo --- Service/CallService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Service/CallService.php b/Service/CallService.php index b9fe75ba..94fe3472 100644 --- a/Service/CallService.php +++ b/Service/CallService.php @@ -2,6 +2,7 @@ namespace CommonGateway\CoreBundle\Service; +// use App\Entity\CallLog; use Adbar\Dot; use App\Entity\Gateway as Source; use Doctrine\ORM\EntityManagerInterface; From a30c977a6b4325c335d91c0955723c1cc6809d9c Mon Sep 17 00:00:00 2001 From: Barry Brands Date: Wed, 15 Feb 2023 16:24:17 +0100 Subject: [PATCH 5/7] small doc fix --- Service/CallService.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Service/CallService.php b/Service/CallService.php index 1cccfe85..6818e838 100644 --- a/Service/CallService.php +++ b/Service/CallService.php @@ -300,10 +300,10 @@ private function getAuthentication(Source $source): array * * @TODO: This is based on some assumptions * - * @param Source $source The source to call - * @param string $endpoint The endpoint on the source to call - * @param array $config The additional configuration to call the source - * @param array $objectsLocation The additional configuration to call the source + * @param Source $source The source to call + * @param string $endpoint The endpoint on the source to call + * @param array $config The additional configuration to call the source + * @param ?string $objectsLocation The additional configuration to call the source * * @return array The array of results */ From abfffa5b1e66f1cb829d4af955b9b6d1f139fecb Mon Sep 17 00:00:00 2001 From: GitHub Actions <> Date: Wed, 15 Feb 2023 15:24:42 +0000 Subject: [PATCH 6/7] Update phpdoc --- docs/classes/Service/CallService.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/classes/Service/CallService.md b/docs/classes/Service/CallService.md index 1f1b19a1..6892a458 100644 --- a/docs/classes/Service/CallService.md +++ b/docs/classes/Service/CallService.md @@ -122,7 +122,7 @@ Decodes a response based on the source it belongs to. **Description** ```php -public getAllResults (\Source $source, string $endpoint, array $config, array $objectsLocation) +public getAllResults (\Source $source, string $endpoint, array $config, ?string $objectsLocation) ``` Fetches all pages for a source and merges the result arrays to one array. @@ -137,7 +137,7 @@ Fetches all pages for a source and merges the result arrays to one array. : The endpoint on the source to call * `(array) $config` : The additional configuration to call the source -* `(array) $objectsLocation` +* `(?string) $objectsLocation` : The additional configuration to call the source **Return Values** From fff9b048104439c0e0aef79793ed99ca3905ba66 Mon Sep 17 00:00:00 2001 From: Barry Brands Date: Fri, 24 Feb 2023 16:13:05 +0100 Subject: [PATCH 7/7] extra check on $config['verify'] --- Service/CallService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Service/CallService.php b/Service/CallService.php index 240cd111..23e6e3c7 100644 --- a/Service/CallService.php +++ b/Service/CallService.php @@ -66,7 +66,7 @@ public function getCertificate(array $config): array $contents = is_array($config['ssl_key']) ? $config['ssl_key'][0] : $config['ssl_key']; $configs['ssl_key'] = $this->fileService->writeFile('privateKey', $contents); } - if (isset($config['verify']) === true && is_string($config['verify']) === true) { + if (isset($config['verify']) === true && empty($config['verify']) === false && is_string($config['verify']) === true) { $configs['verify'] = $this->fileService->writeFile('verify', $config['ssl_key']); } @@ -90,7 +90,7 @@ public function removeFiles(array $config): void $filename = is_array($config['ssl_key']) ? $config['ssl_key'][0] : $config['ssl_key']; $this->fileService->removeFile($filename); } - if (isset($config['verify']) === true && is_string($config['verify']) === true) { + if (isset($config['verify']) === true && empty($config['verify']) === false && is_string($config['verify']) === true) { $this->fileService->removeFile($config['verify']); } }