Skip to content

Class ZugferdKositValidator

HorstOeko edited this page Nov 18, 2024 · 6 revisions

Summary

Class representing the validator against Schematron (Kosit) for documents

Example

Validation of a document read by ZugferdDocumentPdfReader

$kositValidator = new ZugferdKositValidator();

$document = ZugferdDocumentPdfReader::readAndGuessFromFile("/tmp/invoice.pdf");
$kositValidator->setDocument($document)->disableCleanup()->validate();

if ($kositValidator->hasValidationErrors()) {
    echo "Validation failed";
    foreach ($kositValidator->getValidationErrors() as $validationError) {
        echo " - " . $validationError . PHP_EOL;
    }
} else {
    echo "mValidation passed";
}

Validation of a document read by ZugferdDocumentReader

$kositValidator = new ZugferdKositValidator();

$document = ZugferdDocumentReader::readAndGuessFromFile("/tmp/factur-x.xml");
$kositValidator->setDocument($document)->disableCleanup()->validate();

if ($kositValidator->hasValidationErrors()) {
    echo "Validation failed";
    foreach ($kositValidator->getValidationErrors() as $validationError) {
        echo " - " . $validationError . PHP_EOL;
    }
} else {
    echo "mValidation passed";
}

Methods

__construct

Summary

Constructor

Signature

public function __construct(?horstoeko\zugferd\ZugferdDocument $document = null): void;

Parameters

Name Type Allows Null Description
document horstoeko\zugferd\ZugferdDocument ✔️

setDocument

Summary

Set the ZugferdDocument instance to validate

Signature

public function setDocument(horstoeko\zugferd\ZugferdDocument $document): \ZugferdKositValidator;

Parameters

Name Type Allows Null Description
document horstoeko\zugferd\ZugferdDocument

setBaseDirectory

Summary

Setup the base directory. In the base directory all files will be downloaded
and created

Signature

public function setBaseDirectory(string $newBaseDirectory): \ZugferdKositValidator;

Parameters

Name Type Allows Null Description
newBaseDirectory string

setValidatorDownloadUrl

Summary

Setup the KOSIT validator application download url

Signature

public function setValidatorDownloadUrl(string $newValidatorDownloadUrl): \ZugferdKositValidator;

Parameters

Name Type Allows Null Description
newValidatorDownloadUrl string

setValidatorScenarioDownloadUrl

Summary

Setup the KOSIT validator scenario download url

Signature

public function setValidatorScenarioDownloadUrl(string $newValidatorScenarioDownloadUrl): \ZugferdKositValidator;

Parameters

Name Type Allows Null Description
newValidatorScenarioDownloadUrl string

setValidatorAppZipFilename

Summary

Set the filename of the ZIP file which contains the validation application

Signature

public function setValidatorAppZipFilename(string $newValidatorAppZipFilename): \ZugferdKositValidator;

Parameters

Name Type Allows Null Description
newValidatorAppZipFilename string

setValidatorScenarioZipFilename

Summary

Set the filename of the ZIP file which contains the validation scenarios

Signature

public function setValidatorScenarioZipFilename(string $newValidatorScenarioZipFilename): \ZugferdKositValidator;

Parameters

Name Type Allows Null Description
newValidatorScenarioZipFilename string

setValidatorAppJarFilename

Summary

Set the filename of the applications JAR

Signature

public function setValidatorAppJarFilename(string $newValidatorAppJarFilename): \ZugferdKositValidator;

Parameters

Name Type Allows Null Description
newValidatorAppJarFilename string

setValidatorAppScenarioFilename

Summary

Set the filename of the application scenario file

Signature

public function setValidatorAppScenarioFilename(string $newValidatorAppScenarioFilename): \ZugferdKositValidator;

Parameters

Name Type Allows Null Description
newValidatorAppScenarioFilename string

setFileToValidateFilename

Summary

Set the filename of the file which contains the temporary xml data to validate

Signature

public function setFileToValidateFilename(string $newFileToValidateFilename): \ZugferdKositValidator;

Parameters

Name Type Allows Null Description
newFileToValidateFilename string

disableCleanup

Summary

Disable cleanup base directory

Signature

public function disableCleanup(): \ZugferdKositValidator;

enableCleanup

Summary

Enable cleanup base directory

Signature

public function enableCleanup(): \ZugferdKositValidator;

validate

Summary

Perform validation

Signature

public function validate(): \ZugferdKositValidator;

getValidationErrors

Summary

Returns an array of all validation errors

Signature

public function getValidationErrors(): array;

hasNoValidationErrors

Summary

Returns true if no validation errors are present otherwise false

Signature

public function hasNoValidationErrors(): bool;

hasValidationErrors

Summary

Returns true if validation errors are present otherwise false

Signature

public function hasValidationErrors(): bool;

getValidationWarnings

Summary

Returns an array of all validation warnings

Signature

public function getValidationWarnings(): array;

hasNoValidationWarnings

Summary

Returns true if no validation warnings are present otherwise false

Signature

public function hasNoValidationWarnings(): bool;

hasValidationWarnings

Summary

Returns true if validation warnings are present otherwise false

Signature

public function hasValidationWarnings(): bool;

getValidationInformation

Summary

Returns an array of all validation information

Signature

public function getValidationInformation(): array;

hasNoValidationInformation

Summary

Returns true if no validation information are present otherwise false

Signature

public function hasNoValidationInformation(): bool;

hasValidationInformation

Summary

Returns true if validation Information are present otherwise false

Signature

public function hasValidationInformation(): bool;

getProcessErrors

Summary

Return an array of all internal errors (such as download error or system exceptions)

Signature

public function getProcessErrors(): array;

hasNoProcessErrors

Summary

Returns true if there are no system errors (e.g. exceptions before the validation app was called)

Signature

public function hasNoProcessErrors(): bool;

hasProcessErrors

Summary

Returns true if there are any system errors (e.g. exceptions before the validation app was called)

Signature

public function hasProcessErrors(): bool;

getProcessOutput

Summary

Returns an array of all messages from process system (calling external applications)

Signature

public function getProcessOutput(): array;
Clone this wiki locally