From 02c75dd08f38a61f4649172ea3484462d9675922 Mon Sep 17 00:00:00 2001 From: HorstOeko Date: Sat, 26 Oct 2024 11:55:36 +0200 Subject: [PATCH] Added first example --- .gitignore | 1 - examples/.env.example | 9 ++++++++ examples/ExampleHelper.php | 46 ++++++++++++++++++++++++++++++++++++++ examples/ExampleSimple.php | 28 +++++++++++++++++++++++ 4 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 examples/.env.example create mode 100644 examples/ExampleHelper.php create mode 100644 examples/ExampleSimple.php diff --git a/.gitignore b/.gitignore index 9205850..5ae8e33 100644 --- a/.gitignore +++ b/.gitignore @@ -81,7 +81,6 @@ _backup* /*.phar /composer.lock -/examples/Example1.php /examples/config.json !/src/bin /tests/assets/config.save.json diff --git a/examples/.env.example b/examples/.env.example new file mode 100644 index 0000000..e1b626f --- /dev/null +++ b/examples/.env.example @@ -0,0 +1,9 @@ +MAIL_HOST=127.0.0.1 +MAIL_PORT=993 +MAIL_PROTOCOL=imap +MAIL_ENCRYPTION=ssl +MAIL_VALIDATECERT=true +MAIL_USER=demouser +MAIL_PASSWORD=demopassword +MAIL_FOLDERS=INBOX +MAIL_MIMETYPES=text/xml,application/pdf diff --git a/examples/ExampleHelper.php b/examples/ExampleHelper.php new file mode 100644 index 0000000..cb229a4 --- /dev/null +++ b/examples/ExampleHelper.php @@ -0,0 +1,46 @@ +safeLoad(); + $dotEnv->required('MAIL_PORT')->isInteger(); + $dotEnv->required('MAIL_VALIDATECERT')->isBoolean(); + + $mailAccount = $config->addAccount( + 'myaccount-1', + $_ENV['MAIL_HOST'], + filter_var($_ENV['MAIL_PORT'], FILTER_VALIDATE_INT), + $_ENV['MAIL_PROTOCOL'], + $_ENV['MAIL_ENCRYPTION'], + filter_var($_ENV['MAIL_VALIDATECERT'], FILTER_VALIDATE_BOOLEAN), + $_ENV['MAIL_USER'], + $_ENV['MAIL_PASSWORD'] + ); + + $mailAccount->setFoldersToWatch(explode(",", $_ENV['MAIL_FOLDERS'])); + $mailAccount->setMimeTypesToWatch(explode(",", $_ENV['MAIL_MIMETYPES'])); + + return $mailAccount; + } +} diff --git a/examples/ExampleSimple.php b/examples/ExampleSimple.php new file mode 100644 index 0000000..11d628e --- /dev/null +++ b/examples/ExampleSimple.php @@ -0,0 +1,28 @@ +addHandler(new ZugferdMailHandlerSaveToFile('/tmp', 'file.xml')); + +$account->addCallback(function (ZugferdMailAccount $account, Folder $folder, Message $message, Attachment $attachment, ZugferdDocumentReader $document, int $recognitionType) { + $document->getDocumentInformation($documentno, $documenttypecode, $documentdate, $invoiceCurrency, $taxCurrency, $documentname, $documentlanguage, $effectiveSpecifiedPeriod); + echo "Document found ... " . PHP_EOL; + echo "Document No. ..... " . $documentno . PHP_EOL; +}); + +$reader = new ZugferdMailReader($config); +$reader->checkAllAccounts();