commit 01aa6c16c2a66198f1ae9ad63964464cb7e5da52 Author: Abel Hoogeveen Date: Wed Dec 28 10:00:23 2022 +0100 Initial commit diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..91f9bff --- /dev/null +++ b/.drone.yml @@ -0,0 +1,18 @@ +kind: pipeline +type: docker +name: test + +steps: + - name: composer + image: composer:latest + commands: + - composer install + + - name: test + image: registry.i15.nl/i15/fuzephp:8.1-alpine + commands: + - docker-php-ext-enable xdebug + - vendor/bin/phpunit -c test/phpunit.xml + +image_pull_secrets: + - dockerconfig \ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..d6966d7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +.gitattributes export-ignore +.gitignore export-ignore +.drone.yml export-ignore +test/ export-ignore \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1517f7e --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +composer.lock +composer.phar +.idea/ +build/ +test/temp/ +vendor/ +test/.phpunit.result.cache \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ccb7f4f --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2013-2023 i15 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/PHPMailerWrapper.php b/PHPMailerWrapper.php new file mode 100644 index 0000000..0b4f783 --- /dev/null +++ b/PHPMailerWrapper.php @@ -0,0 +1,92 @@ +addComponentPath($libraryPath, Priority::LOWEST); + + // Load config and apply to PHPMailer + $mailerCfg = $config->get("mailer"); + foreach ($mailerCfg->toArray() as $key => $val) + { + if (str_contains($key, '()')) + { + $key = str_replace('()', '', $key); + if (is_array($val)) + $this->{$key}(...$val); + elseif (empty($val)) + $this->{$key}(); + else + $this->{$key}($val); + } + else + $this->{$key} = $val; + } + + } + + /** + * @inheritDoc + */ + public function getClassesPrefix(): ?string + { + return null; + } + + /** + * @inheritDoc + */ + public function getSourceDirectory(): ?string + { + return null; + } +} \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..744e433 --- /dev/null +++ b/composer.json @@ -0,0 +1,37 @@ +{ + "name": "fuzeworks/mailer-wrapper", + "license": ["MIT"], + "authors": [ + { + "name": "Abel Hoogeveen", + "homepage": "https://i15.nl" + } + ], + "require": { + "php": ">=8.1.0", + "fuzeworks/core": "~1.3.0", + "phpmailer/phpmailer": "~6.7", + "ext-ctype": "*", + "ext-filter": "*", + "ext-hash": "*" + }, + "require-dev": { + "phpunit/phpunit": "^9", + "fuzeworks/tracycomponent": "~1.3.0" + }, + "suggest": { + "ext-mbstring": "Needed to send email in multibyte encoding charset or decode encoded addresses", + "ext-openssl": "Needed for secure SMTP sending and DKIM signing", + "greew/oauth2-azure-provider": "Needed for Microsoft Azure XOAUTH2 authentication", + "hayageek/oauth2-yahoo": "Needed for Yahoo XOAUTH2 authentication", + "league/oauth2-google": "Needed for Google XOAUTH2 authentication", + "psr/log": "For optional PSR-3 debug logging", + "thenetworg/oauth2-azure": "Needed for Microsoft XOAUTH2 authentication", + "symfony/polyfill-mbstring": "To support UTF-8 if the Mbstring PHP extension is not enabled (^1.2)" + }, + "autoload": { + "psr-4": { + "FuzeWorks\\Mailer\\": "" + } + } +} \ No newline at end of file diff --git a/config.mailer.php b/config.mailer.php new file mode 100644 index 0000000..e30c40a --- /dev/null +++ b/config.mailer.php @@ -0,0 +1,48 @@ + '', + 'Host' => '', + 'SMTPAuth' => false, + 'Username' => '', + 'Password' => '', + 'SMTPSecure' => '', + 'Port' => 25, + + 'setFrom()' => ['noreply@example.com', 'From name'] + +]; \ No newline at end of file diff --git a/test/base/WrapperTest.php b/test/base/WrapperTest.php new file mode 100644 index 0000000..effe2f7 --- /dev/null +++ b/test/base/WrapperTest.php @@ -0,0 +1,55 @@ +wrapper = \FuzeWorks\Factory::getInstance('libraries')->get('mailer'); + } + + public function testFoundation() + { + $this->assertInstanceOf(PHPMailerWrapper::class, $this->wrapper); + } +} \ No newline at end of file diff --git a/test/bootstrap.php b/test/bootstrap.php new file mode 100644 index 0000000..c3bb9a1 --- /dev/null +++ b/test/bootstrap.php @@ -0,0 +1,56 @@ +setTempDirectory(__DIR__ . '/temp'); +$configurator->setLogDirectory(__DIR__ . '/temp'); + +// Other values +$configurator->setTimeZone('Europe/Amsterdam'); + +// Build the container +$container = $configurator->createContainer(); + +// And add the library +$container->libraries->addLibraryClass("mailer", PHPMailerWrapper::class); +return $container; \ No newline at end of file diff --git a/test/phpunit.xml b/test/phpunit.xml new file mode 100644 index 0000000..f0768eb --- /dev/null +++ b/test/phpunit.xml @@ -0,0 +1,17 @@ + + + + + ../ + + + ../vendor/ + ../test/ + + + + + ./ + + + \ No newline at end of file diff --git a/test/temp/.gitignore b/test/temp/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/test/temp/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file