You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.4 KiB
52 lines
1.4 KiB
1 year ago
|
<?php
|
||
|
class WS_Util
|
||
|
{
|
||
|
public static function CallWebService(string $base_url,string $endpoint, string $method,array $queryParams = [], $requestBody = []) : array {
|
||
|
$url = $base_url . $endpoint;
|
||
|
|
||
|
$options = [
|
||
|
'http' => [
|
||
|
'method' => $method,
|
||
|
'header' => 'Content-Type: application/json', // Remplacez si nécessaire
|
||
|
'ignore_errors' => true, // Gérer les erreurs HTTP
|
||
|
]
|
||
|
];
|
||
|
|
||
|
if (!empty($queryParams)) {
|
||
|
$url .= '?' . http_build_query($queryParams);
|
||
|
}
|
||
|
|
||
|
if (!empty($requestBody)) {
|
||
|
$options['http']['content'] = json_encode($requestBody);
|
||
|
}
|
||
|
|
||
|
$context = stream_context_create($options);
|
||
|
|
||
|
$response = file_get_contents($url, false, $context);
|
||
|
|
||
|
$data = json_decode($response, true);
|
||
|
|
||
|
$retour = [];
|
||
|
$retour = self::AllKeysToUppercase($data);
|
||
|
|
||
|
return $retour;
|
||
|
}
|
||
|
|
||
|
public static function AllKeysToUppercase(?array $data): array
|
||
|
{
|
||
|
$retour = [];
|
||
|
foreach ($data??[] as $cle => $valeur) {
|
||
|
$cleMajuscules = strtoupper($cle);
|
||
|
|
||
|
if (is_array($valeur)) {
|
||
|
$retour[$cleMajuscules] = self::AllKeysToUppercase($valeur);
|
||
|
} else {
|
||
|
$retour[$cleMajuscules] = $valeur;
|
||
|
}
|
||
|
}
|
||
|
return $retour;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|