Préparer la version 1.0.0-rc.4

This commit is contained in:
Alexandre NOEL 2026-09-07 14:15:45 +02:00
commit 6e3beea211
38 changed files with 388 additions and 56 deletions

View file

@ -87,11 +87,12 @@ final class IcadService
throw new RuntimeException(t('service.icad.credentials_missing'));
}
$cookie = sys_get_temp_dir() . '/twix_icad_' . bin2hex(random_bytes(6)) . '.cookie';
$cookie = sys_get_temp_dir() . '/globinours_icad_' . bin2hex(random_bytes(6)) . '.cookie';
try {
// 1) GET HOME => token _token du formulaire login ACTEUR
$r1 = $this->req('https://www.i-cad.fr/', $cookie);
$this->assertSuccess($r1, t('service.icad.home_unavailable'));
$token = $this->extractToken($r1['body'], '_token'); // prend le 1er _token trouvé
@ -109,16 +110,19 @@ final class IcadService
'Origin: https://www.i-cad.fr',
'Referer: https://www.i-cad.fr/',
]);
$this->assertSuccess($r2, t('service.icad.login_failed'));
// 3) Vérif session
$r2b = $this->req('https://www.i-cad.fr/pro', $cookie);
if (stripos($r2b['body'], 'Se connecter') !== false) {
$this->assertSuccess($r2b, t('service.icad.login_failed'));
if (stripos($r2b['body'], 'Se connecter') !== false || str_contains((string)$r2b['effective_url'], '/login')) {
throw new RuntimeException(t('service.icad.login_failed'));
}
// 4) GET recherche. I-CAD a renommé le formulaire
// search_animal en animal_search en 2026 : on accepte les deux.
$r3 = $this->req('https://www.i-cad.fr/identification/recherche', $cookie);
$this->assertSuccess($r3, t('service.icad.search_unavailable'));
[$searchForm, $searchToken] = $this->extractAnimalSearchForm($r3['body']);
// 5) POST recherche
@ -136,6 +140,7 @@ final class IcadService
'Origin: https://www.i-cad.fr',
'Referer: https://www.i-cad.fr/identification/recherche',
]);
$this->assertSuccess($r4, t('service.icad.search_unavailable'));
$animalPath = $this->extractAnimalPath($r4);
if (!$animalPath) {
@ -144,6 +149,7 @@ final class IcadService
// 6) GET fiche animal
$r5 = $this->req('https://www.i-cad.fr' . $animalPath, $cookie);
$this->assertSuccess($r5, t('service.icad.record_unavailable'));
$data = $this->parseAnimalHtml($r5['body'], $animalPath);
$this->saveCache($animalId, $chipId, 'ok', null, $data);
@ -158,6 +164,14 @@ final class IcadService
// ========= HTTP =========
private function assertSuccess(array $response, string $message): void
{
$status = (int) ($response['status'] ?? 0);
if ($status < 200 || $status >= 400) {
throw new RuntimeException($message . ' (HTTP ' . $status . ')');
}
}
private function req(
string $url,
string $cookieFile,