-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
37 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php namespace Nticaric\Fiskalizacija; | ||
|
||
use DOMDocument; | ||
use DOMXPath; | ||
use Exception; | ||
|
||
class ResponseParser | ||
{ | ||
private $document; | ||
private $xpath; | ||
|
||
public function __construct($response) | ||
{ | ||
$this->document = new DOMDocument(); | ||
$this->document->loadXML($response); | ||
$this->xpath = new DOMXPath($this->document); | ||
// Register the namespaces used in the SOAP response | ||
$this->xpath->registerNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/'); | ||
$this->xpath->registerNamespace('tns', 'http://www.apis-it.hr/fin/2012/types/f73'); | ||
} | ||
|
||
public function getJir() | ||
{ | ||
$query = '/soap:Envelope/soap:Body/tns:RacunOdgovor/tns:Jir'; | ||
$entries = $this->xpath->query($query); | ||
if ($entries->length > 0) { | ||
return $entries->item(0)->nodeValue; | ||
} | ||
throw new Exception('JIR value not found in the response'); | ||
} | ||
} |