Files
ednotif-bundle/src/Bovin/Api/BovinApi.php
tristan 7e0c084ebe
All checks were successful
Auto Tag Develop / tag (push) Successful in 5s
Build Release Artefact / build (push) Successful in 36s
feat : restructuration des dossiers pour implementer plus facilement la suite des WS
2026-01-23 16:19:50 +01:00

65 lines
2.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Malio\EdnotifBundle\Bovin\Api;
use Malio\EdnotifBundle\Auth\TokenProvider;
use Malio\EdnotifBundle\Bovin\Dto\AnimalFileDto;
use Malio\EdnotifBundle\Bovin\Mapper\AnimalFileMapper;
use Malio\EdnotifBundle\Shared\Exception\EdnotifException;
use RuntimeException;
use SoapClient;
use SoapFault;
final readonly class BovinApi implements BovinApiInterface
{
public function __construct(
private TokenProvider $tokenProvider,
private SoapClient $businessClient,
private AnimalFileMapper $bovinDossierMapper,
private string $exploitationCountryCode,
private string $exploitationNumber,
) {}
public function getAnimalFile(string $nationalNumber, string $countryCode = 'FR'): AnimalFileDto
{
$token = $this->tokenProvider->getToken();
$requestPayload = [[
'JetonAuthentification' => $token,
'Exploitation' => [
'CodePays' => $this->exploitationCountryCode,
'NumeroExploitation' => $this->exploitationNumber,
],
'Bovin' => [
'CodePays' => $countryCode,
'NumeroNational' => $nationalNumber,
],
]];
try {
/** @var object $soapResponse */
$soapResponse = $this->businessClient->__soapCall('IpBGetDossierAnimal', $requestPayload);
} catch (SoapFault $soapFault) {
throw new RuntimeException('SOAP Fault on IpBGetDossierAnimal: '.$soapFault->getMessage(), 0, $soapFault);
}
// Throw uniquement si Resultat=false (erreur métier)
$standardResponseNode = $soapResponse->ReponseStandard ?? null;
$isOk = is_object($standardResponseNode) && (($standardResponseNode->Resultat ?? false) === true);
if (!$isOk) {
$anomalyNode = is_object($standardResponseNode) ? ($standardResponseNode->Anomalie ?? null) : null;
throw new EdnotifException(
codeAnomalie: (string) ($anomalyNode->Code ?? 'UNKNOWN'),
severite: (int) ($anomalyNode->Severite ?? 1),
message: (string) ($anomalyNode->Message ?? 'EDNOTIF error')
);
}
return $this->bovinDossierMapper->map($soapResponse);
}
}