Skip to content

Commit

Permalink
Merge pull request #36 from horstoeko/kositvalidator
Browse files Browse the repository at this point in the history
Prototype of the ZugferdKositValidator-Class. At present, this feature is still to be considered experimental.
  • Loading branch information
horstoeko authored Apr 12, 2024
2 parents 47730d3 + c847e87 commit 2e8fc63
Show file tree
Hide file tree
Showing 5 changed files with 919 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ _backup*
/nbproject/

!/setup/.htaccess
.vscode
.vscode
.idea

/vendor/
Expand All @@ -83,4 +83,6 @@ _backup*
/composer.lock
/examples/fullpdf.pdf
/examples/factur-x.xml
/examples/filetovalidate-report.xml
/examples/filetovalidate-report.html
myfile_dbg.xml
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,3 +424,7 @@ $mergeToPdf = dirname(__FILE__) . "/fullpdf.pdf";

(new ZugferdDocumentPdfMerger($existingXml, $existingPdf))->generateDocument()->saveDocument($mergeToPdf);
```

### Validation

This library offers several options for checking and validating a document. Please visit the corresponding page in our [Wiki](https://github.com/horstoeko/zugferd/wiki/Validation).
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"setasign/fpdf": "^1",
"setasign/fpdi": "^2",
"symfony/yaml": "^5|^6",
"symfony/process": "^5|^6",
"horstoeko/stringmanagement": "^1",
"horstoeko/mimedb": "^1"
},
Expand Down
56 changes: 56 additions & 0 deletions examples/KositValidator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

use horstoeko\zugferd\ZugferdDocumentReader;
use horstoeko\zugferd\ZugferdKositValidator;
use horstoeko\zugferd\ZugferdDocumentPdfReader;

require dirname(__FILE__) . "/../vendor/autoload.php";

/**
* Helper function for outputting the errors
*
* @param ZugferdKositValidator $kositValidator
* @return void
*/
function showValidationResult(ZugferdKositValidator $kositValidator)
{
if ($kositValidator->hasProcessErrors()) {
echo "\033[01;31mProcess failed\e[0m\n";
foreach ($kositValidator->getProcessErrors() as $processError) {
echo " - " . $processError["message"] . PHP_EOL;
}
} elseif ($kositValidator->hasValidationErrors()) {
echo "\033[01;31mValidation failed\e[0m\n";
foreach ($kositValidator->getValidationErrors() as $validationError) {
echo " - " . $validationError["message"] . PHP_EOL;
}
} else {
echo "\033[01;32mValidation passed\e[0m\n";
}
}

/* ----------------------------------------------------------------------------------
- Get instance of the Validator
---------------------------------------------------------------------------------- */

$kositValidator = new ZugferdKositValidator();

/* ----------------------------------------------------------------------------------
- Validation of a document read by ZugferdDocumentPdfReader
---------------------------------------------------------------------------------- */

$document = ZugferdDocumentPdfReader::readAndGuessFromFile(dirname(__FILE__) . "/invoice_1.pdf");
$kositValidator->setDocument($document)->disableCleanup()->validate();

showValidationResult($kositValidator);

/* ----------------------------------------------------------------------------------
- Validation of a document read by ZugferdDocumentReader
---------------------------------------------------------------------------------- */

$document = ZugferdDocumentReader::readAndGuessFromFile(dirname(__FILE__) . "/../tests/assets/en16931_simple_invalid.xml");

$kositValidator = new ZugferdKositValidator($document);
$kositValidator->setDocument($document)->disableCleanup()->validate();

showValidationResult($kositValidator);
Loading

0 comments on commit 2e8fc63

Please sign in to comment.