Skip to content
Open
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
40 changes: 27 additions & 13 deletions Service/CallService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace CommonGateway\CoreBundle\Service;

//use App\Entity\CallLog;
// use App\Entity\CallLog;
use Adbar\Dot;
use App\Entity\Gateway as Source;
use Doctrine\ORM\EntityManagerInterface;
use GuzzleHttp\Client;
Expand Down Expand Up @@ -65,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']);
}

Expand All @@ -89,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']);
}
}
Expand Down Expand Up @@ -160,6 +161,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
Expand Down Expand Up @@ -298,13 +304,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 ?string $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;
Expand All @@ -330,12 +337,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);
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion docs/classes/Service/CallService.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, ?string $objectsLocation)
```

Fetches all pages for a source and merges the result arrays to one array.
Expand All @@ -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
* `(?string) $objectsLocation`
: The additional configuration to call the source

**Return Values**

Expand Down