Dictionary of versions and namespaces */ private const CFDI_SPECS = [ '4.0' => 'http://www.sat.gob.mx/cfd/4', '3.3' => 'http://www.sat.gob.mx/cfd/3', '3.2' => 'http://www.sat.gob.mx/cfd/3', ]; public function __construct(DOMDocument $document) { $cfdiVersion = new CfdiVersion(); /** @var array $exceptions */ $exceptions = []; foreach (self::CFDI_SPECS as $version => $namespace) { try { $this->loadDocumentWithNamespace($cfdiVersion, $document, $namespace); return; } catch (UnexpectedValueException $exception) { $exceptions[$version] = $exception; } } throw CfdiCreateObjectException::withVersionExceptions($exceptions); } /** @throws UnexpectedValueException */ private function loadDocumentWithNamespace(CfdiVersion $cfdiVersion, DOMDocument $document, string $namespace): void { $rootElement = self::checkRootElement($document, $namespace, 'cfdi', 'Comprobante'); $this->version = $cfdiVersion->getFromDOMElement($rootElement); $this->document = clone $document; } }