Skip to content

Commit d262d2b

Browse files
author
Lucas Gouy-Pailler
committed
Fix not defined profil when not check XSD and adding logo
1 parent 537b215 commit d262d2b

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/Facturx.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,15 @@ public function checkFacturxXsd($facturxXml, $facturxProfil = 'autodetect')
137137
throw new \Exception('$facturxXml argument must be a file or a string');
138138
}
139139

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;
146148
}
147-
$this->profil = $facturxProfil;
148149
$xsdFilename = static::FACTURX_PROFIL_TO_XSD[$this->profil];
149150
$xsdFile = __DIR__.'/../xsd/'.$xsdFilename;
150151
try {
@@ -216,6 +217,15 @@ public function generateFacturxFromFiles(
216217
$docFacturx = new \DOMDocument();
217218
$docFacturx->loadXML($xmlString);
218219

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+
219229
if (true == $checkXsd) {
220230
// The profil is validated inside checkFacturxXsd
221231
$this->checkFacturxXsd($facturxXml, $facturxProfil);

0 commit comments

Comments
 (0)