Skip to content

Commit

Permalink
[ENH] Improved KositValidator remote validation
Browse files Browse the repository at this point in the history
  • Loading branch information
HorstOeko committed Dec 15, 2024
1 parent 336aa8e commit c09ef7e
Showing 1 changed file with 35 additions and 12 deletions.
47 changes: 35 additions & 12 deletions src/ZugferdKositValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public function enableRemoteMode(): ZugferdKositValidator
* Set the hostname or the ip of the remote host where the validation application
* is running in daemon mode
*
* @param string $remoteModeHost
* @param string $remoteModeHost
* @return ZugferdKositValidator
*/
public function setRemoteModeHost(string $remoteModeHost): ZugferdKositValidator
Expand All @@ -358,7 +358,7 @@ public function setRemoteModeHost(string $remoteModeHost): ZugferdKositValidator
* Set the port of the remote host where the validation application
* is running in daemon mode
*
* @param integer $remoteModePort
* @param integer $remoteModePort
* @return ZugferdKositValidator
*/
public function setRemoteModePort(int $remoteModePort): ZugferdKositValidator
Expand Down Expand Up @@ -732,18 +732,30 @@ private function checkRequirementsRemote(): bool

try {
$httpConnection = curl_init($this->getRemoteModeUrl());

curl_setopt($httpConnection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($httpConnection, CURLOPT_HEADER, true);
curl_setopt($httpConnection, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($httpConnection, CURLOPT_ENCODING, '');
curl_setopt($httpConnection, CURLOPT_AUTOREFERER, true);
curl_setopt($httpConnection, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($httpConnection, CURLOPT_TIMEOUT, 10);
curl_exec($httpConnection);
$retcode = curl_getinfo($httpConnection, CURLINFO_HTTP_CODE);
curl_setopt($httpConnection, CURLOPT_TIMEOUT, 120);

$response = curl_exec($httpConnection);

if ($response === false) {
$this->addToMessageBag("Failed to connect to the host where the Validator is running in daemon mode");
$this->addToMessageBag(curl_error($httpConnection));
return false;
}

$responseStatusCode = curl_getinfo($httpConnection, CURLINFO_HTTP_CODE);

curl_close($httpConnection);
if ($retcode != 200) {

if (($responseStatusCode < 200) || ($responseStatusCode >= 400)) {
$this->addToMessageBag("Failed to connect to the host where the Validator is running in daemon mode");
$this->addToMessageBag(curl_error($httpConnection));
return false;
}
} catch (Throwable $e) {
Expand Down Expand Up @@ -911,6 +923,7 @@ private function performValidationRemote(): bool

try {
$httpConnection = curl_init($this->getRemoteModeUrl());

curl_setopt($httpConnection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($httpConnection, CURLOPT_HEADER, true);
curl_setopt($httpConnection, CURLOPT_FOLLOWLOCATION, true);
Expand All @@ -921,11 +934,21 @@ private function performValidationRemote(): bool
curl_setopt($httpConnection, CURLOPT_POST, true);
curl_setopt($httpConnection, CURLOPT_POSTFIELDS, $this->document->serializeAsXml());
curl_setopt($httpConnection, CURLOPT_HTTPHEADER, ["Content-Type: application/xml"]);
$responseXml = curl_exec($httpConnection);
$retcode = curl_getinfo($httpConnection, CURLINFO_HTTP_CODE);

$response = curl_exec($httpConnection);

if ($response === false) {
$this->addToMessageBag("Failed to connect to the host where the Validator is running in daemon mode");
$this->addToMessageBag(curl_error($httpConnection));
return false;
}

$responseStatusCode = curl_getinfo($httpConnection, CURLINFO_HTTP_CODE);

curl_close($httpConnection);
if ($retcode != 200) {
if (preg_match('/<\?xml.*?\?>.*<\/.+>/s', $responseXml, $matches)) {

if (($responseStatusCode < 200) || ($responseStatusCode >= 400)) {
if (preg_match('/<\?xml.*?\?>.*<\/.+>/s', $response, $matches)) {
$this->parseValidatorXmlReportByContent($matches[0]);
}
return false;
Expand Down Expand Up @@ -966,7 +989,7 @@ private function parseValidatorXmlReportByFile(): void
* Parses the XML content string containing the response from the validation app (JAVA application) and put errors
* to messagebag
*
* @param string $xmlContent
* @param string $xmlContent
* @return void
*/
private function parseValidatorXmlReportByContent(string $xmlContent): void
Expand All @@ -985,7 +1008,7 @@ private function parseValidatorXmlReportByContent(string $xmlContent): void
* Parses the XML DOMDocument containing the response from the validation app (JAVA application) and put errors
* to messagebag
*
* @param DOMDocument $domDocument
* @param DOMDocument $domDocument
* @return void
*/
private function parseValidatorXmlReportByDomDocument(DOMDocument $domDocument): void
Expand Down

0 comments on commit c09ef7e

Please sign in to comment.