Skip to content

Commit

Permalink
Remove ns2 namespace from response of queryTaxpayer XML element
Browse files Browse the repository at this point in the history
  • Loading branch information
pzs committed Mar 16, 2020
1 parent 0cb3d6d commit 3b1da22
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ $reporter = new NavOnlineInvoice\Reporter($config);

### Adószám ellenőrzése (`queryTaxpayer`)

Megjegyzés: a modul automatikusan eltávolítja az `ns2` namespace-t a válasz XML-ből (lásd [#20](https://github.com/pzs/nav-online-invoice/issues/20)), így kényelmesebben használható az XML válasz. Ez a működés szükség szerint kikapcsolható a `$config->removeNamespaces` `false`-ra állításával.

```php
try {
$result = $reporter->queryTaxpayer("12345678");
Expand Down
3 changes: 3 additions & 0 deletions src/NavOnlineInvoice/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class Config {

public $curlTimeout = null;

// `queryTaxpayer` válasz XML-jében a 'ns2' automatikus eltávolítása
public $removeNamespaces = true;

/** @var RequestIdGeneratorInterface */
public $requestIdGenerator;

Expand Down
8 changes: 7 additions & 1 deletion src/NavOnlineInvoice/Reporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,14 @@ public function queryTaxpayer($taxNumber) {
return false;
}

if ($this->config->removeNamespaces) {
$taxpayerData = XmlUtil::removeNamespaces($responseXml->taxpayerData);
} else {
$taxpayerData = $responseXml->taxpayerData;
}

// Az adószám valid, adózó adatainak visszaadása
return $responseXml->taxpayerData;
return $taxpayerData;
}


Expand Down
17 changes: 17 additions & 0 deletions src/NavOnlineInvoice/XmlUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,21 @@ public static function addChildArray(\SimpleXMLElement $xmlNode, $name, $data) {
}
}


/**
* Remove namespaces from XML elements
*
* @param \SimpleXMLElement $xmlNode
* @return \SimpleXMLElement $xmlNode
*/
public static function removeNamespaces(\SimpleXMLElement $xmlNode) {
$xmlString = $xmlNode->asXML();

$cleanedXmlString = preg_replace('/(<\/|<)[a-z0-9]+:([a-z0-9]+[ =>])/i', '$1$2', $xmlString);

$cleanedXmlNode = simplexml_load_string($cleanedXmlString);

return $cleanedXmlNode;
}

}

0 comments on commit 3b1da22

Please sign in to comment.