readFirstEntry($tempFile); } finally { @unlink($tempFile); } $previous = libxml_use_internal_errors(true); try { $simpleXml = simplexml_load_string($xml); } finally { libxml_clear_errors(); libxml_use_internal_errors($previous); } if (false === $simpleXml) { throw new RuntimeException('ZipMessageDecoder: XML invalide dans l\'archive ZIP.'); } $json = json_encode($simpleXml); if (false === $json) { throw new RuntimeException('ZipMessageDecoder: échec de l\'encodage JSON intermédiaire.'); } $decoded = json_decode($json, false); if (!is_object($decoded)) { throw new RuntimeException('ZipMessageDecoder: décodage JSON non objet.'); } return $decoded; } private function readFirstEntry(string $filePath): string { $zip = new ZipArchive(); $openResult = $zip->open($filePath, ZipArchive::RDONLY); if (true !== $openResult) { throw new RuntimeException(sprintf('ZipMessageDecoder: ouverture ZIP impossible (code %s).', (string) $openResult)); } try { if (0 === $zip->numFiles) { throw new RuntimeException('ZipMessageDecoder: archive ZIP vide.'); } $xml = $zip->getFromIndex(0); if (false === $xml) { throw new RuntimeException('ZipMessageDecoder: lecture de l\'entrée ZIP impossible.'); } } finally { $zip->close(); } return $xml; } }