Dictionary of versions and namespaces */ private const RET_SPECS = [ '2.0' => 'http://www.sat.gob.mx/esquemas/retencionpago/2', '1.0' => 'http://www.sat.gob.mx/esquemas/retencionpago/1', ]; public function __construct(DOMDocument $document) { $retVersion = new RetencionVersion(); /** @var array $exceptions */ $exceptions = []; foreach (self::RET_SPECS as $version => $namespace) { try { $this->loadDocumentWithNamespace($retVersion, $document, $namespace); return; } catch (UnexpectedValueException $exception) { $exceptions[$version] = $exception; } } throw CfdiCreateObjectException::withVersionExceptions($exceptions); } /** @throws UnexpectedValueException */ private function loadDocumentWithNamespace( RetencionVersion $retVersion, DOMDocument $document, string $namespace ): void { $rootElement = self::checkRootElement($document, $namespace, 'retenciones', 'Retenciones'); $this->version = $retVersion->getFromDOMElement($rootElement); $this->document = clone $document; } }