|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace DNB;
|
|
namespace DNB;
|
|
|
|
|
|
|
|
+use HaydenPierce\ClassFinder\ClassFinder;
|
|
use Symfony\Component\HttpClient\HttpClient;
|
|
use Symfony\Component\HttpClient\HttpClient;
|
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
|
|
|
|
|
@@ -70,12 +71,27 @@ final class Client {
|
|
]);
|
|
]);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private function findInNamespace(string $ns): ?string {
|
|
|
|
+ $classes = array_filter(ClassFinder::getClassesInNamespace(
|
|
|
|
+ dirname(str_replace('\\', DIRECTORY_SEPARATOR, self::class))
|
|
|
|
+ ), function (string $class) {
|
|
|
|
+ return class_implements($class, AbstractPostSerializable::class) && strpos($class, AbstractPostSerializable::class) !== 0;
|
|
|
|
+ });
|
|
|
|
+ var_dump($classes);
|
|
|
|
+
|
|
|
|
+ $key = array_search(strtolower($ns), array_map(function (string $class): string {
|
|
|
|
+ return $class::namespace();
|
|
|
|
+ }, $classes));
|
|
|
|
+
|
|
|
|
+ return $key ? $classes[$key] : null;
|
|
|
|
+ }
|
|
|
|
+
|
|
public function orderProspectus(
|
|
public function orderProspectus(
|
|
Prospectus $prospectus
|
|
Prospectus $prospectus
|
|
): bool {
|
|
): bool {
|
|
$ret = $this->getAuthClient()->request(
|
|
$ret = $this->getAuthClient()->request(
|
|
"POST",
|
|
"POST",
|
|
- 'https://uat-process-externalpart.azurewebsites.net/api/v1/autoprospect/orderprospect', [
|
|
|
|
|
|
+ $this->getUrl($this->clientConfig->get()->endpoint, '/api/v1/autoprospect/orderprospect'), [
|
|
'json' => $prospectus->toPostParams(),
|
|
'json' => $prospectus->toPostParams(),
|
|
]
|
|
]
|
|
);
|
|
);
|
|
@@ -83,8 +99,30 @@ final class Client {
|
|
$ret->getContent();
|
|
$ret->getContent();
|
|
return true;
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
- $content = $ret->getContent(false);
|
|
|
|
- throw new \InvalidArgumentException(!empty($content) ? $content : $e->getMessage(), $e->getCode(), $e);
|
|
|
|
|
|
+ $content = json_decode($ret->getContent(false), true);
|
|
|
|
+
|
|
|
|
+ if (json_last_error() == JSON_ERROR_NONE) {
|
|
|
|
+ foreach ($content as $key => $value) {
|
|
|
|
+ $scope = explode('.', $key);
|
|
|
|
+
|
|
|
|
+ if (sizeof($scope) <= 1)
|
|
|
|
+ continue;
|
|
|
|
+
|
|
|
|
+ $ns = $this->findInNamespace($scope[0]);
|
|
|
|
+
|
|
|
|
+ foreach (array_keys($ns::getPostParams()) as $param) {
|
|
|
|
+ if (strpos(strtolower($param), strtolower($scope[1])) == strlen($ns::namespace())+1) {
|
|
|
|
+ unset($content[$key]);
|
|
|
|
+ $content[$param] = $value;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ $content = json_encode($content);
|
|
|
|
+ } else
|
|
|
|
+ $content = $e->getMessage();
|
|
|
|
+
|
|
|
|
+ throw new \InvalidArgumentException($content, $e->getCode(), $e);
|
|
}
|
|
}
|
|
|
|
|
|
return false;
|
|
return false;
|