@@ -137,14 +137,15 @@ public function checkFacturxXsd($facturxXml, $facturxProfil = 'autodetect')
137
137
throw new \Exception ('$facturxXml argument must be a file or a string ' );
138
138
}
139
139
140
- if ($ facturxProfil === 'autodetect ' ) {
141
- $ facturxProfil = $ this ->getFacturxProfil ($ doc );
142
- }
143
-
144
- if (!array_key_exists ($ facturxProfil , static ::FACTURX_PROFIL_TO_XSD )) {
145
- throw new \Exception ("Wrong profil ' $ facturxProfil' for Factur-X invoice. " );
140
+ if (!$ this ->profil ) {
141
+ if ($ facturxProfil === 'autodetect ' ) {
142
+ $ facturxProfil = $ this ->getFacturxProfil ($ doc );
143
+ }
144
+ if (!array_key_exists ($ facturxProfil , static ::FACTURX_PROFIL_TO_XSD )) {
145
+ throw new \Exception ("Wrong profil ' $ facturxProfil' for Factur-X invoice. " );
146
+ }
147
+ $ this ->profil = $ facturxProfil ;
146
148
}
147
- $ this ->profil = $ facturxProfil ;
148
149
$ xsdFilename = static ::FACTURX_PROFIL_TO_XSD [$ this ->profil ];
149
150
$ xsdFile = __DIR__ .'/../xsd/ ' .$ xsdFilename ;
150
151
try {
@@ -216,6 +217,15 @@ public function generateFacturxFromFiles(
216
217
$ docFacturx = new \DOMDocument ();
217
218
$ docFacturx ->loadXML ($ xmlString );
218
219
220
+ if ($ facturxProfil === 'autodetect ' ) {
221
+ $ facturxProfil = $ this ->getFacturxProfil ($ docFacturx );
222
+ }
223
+
224
+ if (!array_key_exists ($ facturxProfil , static ::FACTURX_PROFIL_TO_XSD )) {
225
+ throw new \Exception ("Wrong profil ' $ facturxProfil' for Factur-X invoice. " );
226
+ }
227
+ $ this ->profil = $ facturxProfil ;
228
+
219
229
if (true == $ checkXsd ) {
220
230
// The profil is validated inside checkFacturxXsd
221
231
$ this ->checkFacturxXsd ($ facturxXml , $ facturxProfil );
0 commit comments