This commit is contained in:
2024-03-10 23:21:23 -04:00
parent 69a3c3f157
commit 562b740d68
4 changed files with 500 additions and 145 deletions

View File

@@ -16,9 +16,9 @@
},
"minimum-stability": "dev",
"require": {
"php": ">=7.0.0",
"php": ">=8.3.0",
"psr/log": "^1.0",
"psr/simple-cache": "^1.0",
"guzzlehttp/guzzle": "^6.3"
"guzzlehttp/guzzle": "^7.8"
}
}

506
composer.lock generated
View File

@@ -1,42 +1,54 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "e6242594ada0bd472c34ec3bbac0645e",
"content-hash": "8820aa0f3afb4adb8d82e3d78f65c487",
"packages": [
{
"name": "guzzlehttp/guzzle",
"version": "6.3.0",
"version": "7.8.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
"reference": "f4db5a78a5ea468d4831de7f0bf9d9415e348699"
"reference": "1110f66a6530a40fe7aea0378fe608ee2b2248f9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/f4db5a78a5ea468d4831de7f0bf9d9415e348699",
"reference": "f4db5a78a5ea468d4831de7f0bf9d9415e348699",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/1110f66a6530a40fe7aea0378fe608ee2b2248f9",
"reference": "1110f66a6530a40fe7aea0378fe608ee2b2248f9",
"shasum": ""
},
"require": {
"guzzlehttp/promises": "^1.0",
"guzzlehttp/psr7": "^1.4",
"php": ">=5.5"
"ext-json": "*",
"guzzlehttp/promises": "^1.5.3 || ^2.0.1",
"guzzlehttp/psr7": "^1.9.1 || ^2.5.1",
"php": "^7.2.5 || ^8.0",
"psr/http-client": "^1.0",
"symfony/deprecation-contracts": "^2.2 || ^3.0"
},
"provide": {
"psr/http-client-implementation": "1.0"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8.1",
"ext-curl": "*",
"phpunit/phpunit": "^4.0 || ^5.0",
"psr/log": "^1.0"
"php-http/client-integration-tests": "dev-master#2c025848417c1135031fdf9c728ee53d0a7ceaee as 3.0.999",
"php-http/message-factory": "^1.1",
"phpunit/phpunit": "^8.5.29 || ^9.5.23",
"psr/log": "^1.1 || ^2.0 || ^3.0"
},
"suggest": {
"ext-curl": "Required for CURL handler support",
"ext-intl": "Required for Internationalized Domain Name (IDN) support",
"psr/log": "Required for using the Log middleware"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "6.2-dev"
"bamarni-bin": {
"bin-links": true,
"forward-command": false
}
},
"autoload": {
@@ -52,158 +64,347 @@
"MIT"
],
"authors": [
{
"name": "Graham Campbell",
"email": "hello@gjcampbell.co.uk",
"homepage": "https://github.com/GrahamCampbell"
},
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "Jeremy Lindblom",
"email": "jeremeamia@gmail.com",
"homepage": "https://github.com/jeremeamia"
},
{
"name": "George Mponos",
"email": "gmponos@gmail.com",
"homepage": "https://github.com/gmponos"
},
{
"name": "Tobias Nyholm",
"email": "tobias.nyholm@gmail.com",
"homepage": "https://github.com/Nyholm"
},
{
"name": "Márk Sági-Kazár",
"email": "mark.sagikazar@gmail.com",
"homepage": "https://github.com/sagikazarmark"
},
{
"name": "Tobias Schultze",
"email": "webmaster@tubo-world.de",
"homepage": "https://github.com/Tobion"
}
],
"description": "Guzzle is a PHP HTTP client library",
"homepage": "http://guzzlephp.org/",
"keywords": [
"client",
"curl",
"framework",
"http",
"http client",
"psr-18",
"psr-7",
"rest",
"web service"
],
"time": "2017-06-22T18:50:49+00:00"
"support": {
"issues": "https://github.com/guzzle/guzzle/issues",
"source": "https://github.com/guzzle/guzzle/tree/7.8.0"
},
"funding": [
{
"url": "https://github.com/GrahamCampbell",
"type": "github"
},
{
"url": "https://github.com/Nyholm",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/guzzlehttp/guzzle",
"type": "tidelift"
}
],
"time": "2023-08-27T10:20:53+00:00"
},
{
"name": "guzzlehttp/promises",
"version": "dev-master",
"version": "2.0.x-dev",
"source": {
"type": "git",
"url": "https://github.com/guzzle/promises.git",
"reference": "09e549f5534380c68761260a71f847644d8f65aa"
"reference": "bbff78d96034045e58e13dedd6ad91b5d1253223"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/promises/zipball/09e549f5534380c68761260a71f847644d8f65aa",
"reference": "09e549f5534380c68761260a71f847644d8f65aa",
"url": "https://api.github.com/repos/guzzle/promises/zipball/bbff78d96034045e58e13dedd6ad91b5d1253223",
"reference": "bbff78d96034045e58e13dedd6ad91b5d1253223",
"shasum": ""
},
"require": {
"php": ">=5.5.0"
"php": "^7.2.5 || ^8.0"
},
"require-dev": {
"phpunit/phpunit": "^4.0"
"bamarni/composer-bin-plugin": "^1.8.2",
"phpunit/phpunit": "^8.5.36 || ^9.6.15"
},
"default-branch": true,
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4-dev"
"bamarni-bin": {
"bin-links": true,
"forward-command": false
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Promise\\": "src/"
},
"files": [
"src/functions_include.php"
]
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Graham Campbell",
"email": "hello@gjcampbell.co.uk",
"homepage": "https://github.com/GrahamCampbell"
},
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "Tobias Nyholm",
"email": "tobias.nyholm@gmail.com",
"homepage": "https://github.com/Nyholm"
},
{
"name": "Tobias Schultze",
"email": "webmaster@tubo-world.de",
"homepage": "https://github.com/Tobion"
}
],
"description": "Guzzle promises library",
"keywords": [
"promise"
],
"time": "2017-05-20T23:14:18+00:00"
"support": {
"issues": "https://github.com/guzzle/promises/issues",
"source": "https://github.com/guzzle/promises/tree/2.0.2"
},
"funding": [
{
"url": "https://github.com/GrahamCampbell",
"type": "github"
},
{
"url": "https://github.com/Nyholm",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/guzzlehttp/promises",
"type": "tidelift"
}
],
"time": "2023-12-03T20:19:20+00:00"
},
{
"name": "guzzlehttp/psr7",
"version": "dev-master",
"version": "2.6.x-dev",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "811b676fbab9c99e359885032e5ebc70e442f5b8"
"reference": "45b30f99ac27b5ca93cb4831afe16285f57b8221"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/811b676fbab9c99e359885032e5ebc70e442f5b8",
"reference": "811b676fbab9c99e359885032e5ebc70e442f5b8",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/45b30f99ac27b5ca93cb4831afe16285f57b8221",
"reference": "45b30f99ac27b5ca93cb4831afe16285f57b8221",
"shasum": ""
},
"require": {
"php": ">=5.4.0",
"psr/http-message": "~1.0"
"php": "^7.2.5 || ^8.0",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.1 || ^2.0",
"ralouphie/getallheaders": "^3.0"
},
"provide": {
"psr/http-factory-implementation": "1.0",
"psr/http-message-implementation": "1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
"bamarni/composer-bin-plugin": "^1.8.2",
"http-interop/http-factory-tests": "^0.9",
"phpunit/phpunit": "^8.5.36 || ^9.6.15"
},
"suggest": {
"laminas/laminas-httphandlerrunner": "Emit PSR-7 responses"
},
"default-branch": true,
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4-dev"
"bamarni-bin": {
"bin-links": true,
"forward-command": false
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Psr7\\": "src/"
},
"files": [
"src/functions_include.php"
]
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Graham Campbell",
"email": "hello@gjcampbell.co.uk",
"homepage": "https://github.com/GrahamCampbell"
},
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "George Mponos",
"email": "gmponos@gmail.com",
"homepage": "https://github.com/gmponos"
},
{
"name": "Tobias Nyholm",
"email": "tobias.nyholm@gmail.com",
"homepage": "https://github.com/Nyholm"
},
{
"name": "Márk Sági-Kazár",
"email": "mark.sagikazar@gmail.com",
"homepage": "https://github.com/sagikazarmark"
},
{
"name": "Tobias Schultze",
"email": "webmaster@tubo-world.de",
"homepage": "https://github.com/Tobion"
},
{
"name": "Márk Sági-Kazár",
"email": "mark.sagikazar@gmail.com",
"homepage": "https://sagikazarmark.hu"
}
],
"description": "PSR-7 message implementation that also provides common utility methods",
"keywords": [
"http",
"message",
"psr-7",
"request",
"response",
"stream",
"uri",
"url"
],
"time": "2017-07-17T09:11:21+00:00"
"support": {
"issues": "https://github.com/guzzle/psr7/issues",
"source": "https://github.com/guzzle/psr7/tree/2.6.2"
},
"funding": [
{
"url": "https://github.com/GrahamCampbell",
"type": "github"
},
{
"url": "https://github.com/Nyholm",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/guzzlehttp/psr7",
"type": "tidelift"
}
],
"time": "2023-12-03T20:05:35+00:00"
},
{
"name": "psr/http-message",
"name": "psr/http-client",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-message.git",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363"
"url": "https://github.com/php-fig/http-client.git",
"reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363",
"url": "https://api.github.com/repos/php-fig/http-client/zipball/bb5906edc1c324c9a05aa0873d40117941e5fa90",
"reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
"php": "^7.0 || ^8.0",
"psr/http-message": "^1.0 || ^2.0"
},
"default-branch": true,
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Http\\Client\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"description": "Common interface for HTTP clients",
"homepage": "https://github.com/php-fig/http-client",
"keywords": [
"http",
"http-client",
"psr",
"psr-18"
],
"support": {
"source": "https://github.com/php-fig/http-client"
},
"time": "2023-09-23T14:17:50+00:00"
},
{
"name": "psr/http-factory",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-factory.git",
"reference": "7037f4b0950474e9d1350e8df89b15f1842085f6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-factory/zipball/7037f4b0950474e9d1350e8df89b15f1842085f6",
"reference": "7037f4b0950474e9d1350e8df89b15f1842085f6",
"shasum": ""
},
"require": {
"php": ">=7.0.0",
"psr/http-message": "^1.0 || ^2.0"
},
"default-branch": true,
"type": "library",
"extra": {
"branch-alias": {
@@ -222,7 +423,62 @@
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
"homepage": "https://www.php-fig.org/"
}
],
"description": "PSR-17: Common interfaces for PSR-7 HTTP message factories",
"keywords": [
"factory",
"http",
"message",
"psr",
"psr-17",
"psr-7",
"request",
"response"
],
"support": {
"source": "https://github.com/php-fig/http-factory"
},
"time": "2023-09-22T11:16:44+00:00"
},
{
"name": "psr/http-message",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-message.git",
"reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71",
"reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71",
"shasum": ""
},
"require": {
"php": "^7.2 || ^8.0"
},
"default-branch": true,
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Http\\Message\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"description": "Common interface for HTTP messages",
@@ -235,20 +491,23 @@
"request",
"response"
],
"time": "2016-08-06T14:39:51+00:00"
"support": {
"source": "https://github.com/php-fig/http-message/tree/2.0"
},
"time": "2023-04-04T09:54:51+00:00"
},
{
"name": "psr/log",
"version": "dev-master",
"version": "1.1.4",
"source": {
"type": "git",
"url": "https://github.com/php-fig/log.git",
"reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d"
"reference": "d49695b909c3b7628b6289db5479a1c204601f11"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d",
"reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d",
"url": "https://api.github.com/repos/php-fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11",
"reference": "d49695b909c3b7628b6289db5479a1c204601f11",
"shasum": ""
},
"require": {
@@ -257,7 +516,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
"dev-master": "1.1.x-dev"
}
},
"autoload": {
@@ -272,7 +531,7 @@
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
"homepage": "https://www.php-fig.org/"
}
],
"description": "Common interface for logging libraries",
@@ -282,20 +541,23 @@
"psr",
"psr-3"
],
"time": "2016-10-10T12:19:37+00:00"
"support": {
"source": "https://github.com/php-fig/log/tree/1.1.4"
},
"time": "2021-05-03T11:20:27+00:00"
},
{
"name": "psr/simple-cache",
"version": "dev-master",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/php-fig/simple-cache.git",
"reference": "753fa598e8f3b9966c886fe13f370baa45ef0e24"
"reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/simple-cache/zipball/753fa598e8f3b9966c886fe13f370baa45ef0e24",
"reference": "753fa598e8f3b9966c886fe13f370baa45ef0e24",
"url": "https://api.github.com/repos/php-fig/simple-cache/zipball/408d5eafb83c57f6365a3ca330ff23aa4a5fa39b",
"reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b",
"shasum": ""
},
"require": {
@@ -330,7 +592,122 @@
"psr-16",
"simple-cache"
],
"time": "2017-01-02T13:31:39+00:00"
"support": {
"source": "https://github.com/php-fig/simple-cache/tree/master"
},
"time": "2017-10-23T01:57:42+00:00"
},
{
"name": "ralouphie/getallheaders",
"version": "3.0.3",
"source": {
"type": "git",
"url": "https://github.com/ralouphie/getallheaders.git",
"reference": "120b605dfeb996808c31b6477290a714d356e822"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822",
"reference": "120b605dfeb996808c31b6477290a714d356e822",
"shasum": ""
},
"require": {
"php": ">=5.6"
},
"require-dev": {
"php-coveralls/php-coveralls": "^2.1",
"phpunit/phpunit": "^5 || ^6.5"
},
"type": "library",
"autoload": {
"files": [
"src/getallheaders.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Ralph Khattar",
"email": "ralph.khattar@gmail.com"
}
],
"description": "A polyfill for getallheaders.",
"support": {
"issues": "https://github.com/ralouphie/getallheaders/issues",
"source": "https://github.com/ralouphie/getallheaders/tree/develop"
},
"time": "2019-03-08T08:55:37+00:00"
},
{
"name": "symfony/deprecation-contracts",
"version": "dev-main",
"source": {
"type": "git",
"url": "https://github.com/symfony/deprecation-contracts.git",
"reference": "2c438b99bb2753c1628c1e6f523991edea5b03a4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/2c438b99bb2753c1628c1e6f523991edea5b03a4",
"reference": "2c438b99bb2753c1628c1e6f523991edea5b03a4",
"shasum": ""
},
"require": {
"php": ">=8.1"
},
"default-branch": true,
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "3.5-dev"
},
"thanks": {
"name": "symfony/contracts",
"url": "https://github.com/symfony/contracts"
}
},
"autoload": {
"files": [
"function.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "A generic function and convention to trigger deprecation notices",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/deprecation-contracts/tree/main"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2024-01-02T14:07:37+00:00"
}
],
"packages-dev": [],
@@ -340,7 +717,8 @@
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
"php": ">=7.0.0"
"php": ">=8.3.0"
},
"platform-dev": []
"platform-dev": [],
"plugin-api-version": "2.6.0"
}

View File

@@ -15,57 +15,57 @@ class Client
/**
* @var TransportInterface
*/
private $_transport;
private TransportInterface $_transport;
/**
* @var array
*/
private $_to = [];
private array $_to = [];
/**
* @var array
*/
private $_cc = [];
private array $_cc = [];
/**
* @var array
*/
private $_bcc = [];
private array $_bcc = [];
/**
* @var array
*/
private $_files = [];
private array $_files = [];
/**
* @var string
*/
private $_from = '';
private string $_from = '';
/**
* @var string
*/
private $_subject = '(No Subject)';
private string $_subject = '(No Subject)';
/**
* @var string
*/
private $_body = '';
private string $_body = '';
/**
* @var bool
*/
private $_isHtml = false;
private bool $_isHtml = false;
/**
* @var bool
*/
private $_catch = false;
private bool $_catch = false;
/**
* @var bool|\DateTimeInterface
*/
private $_sendTime = false;
private bool|\DateTimeInterface $_sendTime = false;
/**
* Client constructor.
@@ -81,7 +81,7 @@ class Client
* @param string $to
* @throws ValidationException
*/
public function addTo(string $to)
public function addTo(string $to): void
{
if (!Validator::validateEmailAddress($to)) {
throw new ValidationException('Email address is invalid');
@@ -95,7 +95,7 @@ class Client
* @param array $to
* @throws ValidationException
*/
public function setAllTo(array $to)
public function setAllTo(array $to): void
{
foreach ($to as $item) {
if (!Validator::validateEmailAddress($item)) {
@@ -110,7 +110,7 @@ class Client
* @param string $cc
* @throws ValidationException
*/
public function addCc(string $cc)
public function addCc(string $cc): void
{
if (!Validator::validateEmailAddress($cc)) {
throw new ValidationException('Email address is invalid');
@@ -123,7 +123,7 @@ class Client
* @param string $bcc
* @throws ValidationException
*/
public function addBcc(string $bcc)
public function addBcc(string $bcc): void
{
if (!Validator::validateEmailAddress($bcc)) {
throw new ValidationException('Email address is invalid');
@@ -136,7 +136,7 @@ class Client
* @param string $body
* @param bool $isHtml
*/
public function setBody(string $body, bool $isHtml = false)
public function setBody(string $body, bool $isHtml = false): void
{
$this->_body = $body;
$this->_isHtml = $isHtml;
@@ -145,7 +145,7 @@ class Client
/**
* @param string $subject
*/
public function setSubject(string $subject)
public function setSubject(string $subject): void
{
$this->_subject = $subject;
}
@@ -155,7 +155,7 @@ class Client
*
* @throws ValidationException
*/
public function setFrom(string $from)
public function setFrom(string $from): void
{
if (!Validator::validateEmailAddress($from)) {
throw new ValidationException('Email address is invalid');
@@ -169,7 +169,7 @@ class Client
* @throws ValidationException
* @return mixed
*/
public function send(bool $catch = false)
public function send(bool $catch = false): mixed
{
$this->_catch = $catch;
$payload = $this->_buildPayload();
@@ -249,7 +249,7 @@ class Client
/**
* @throws ValidationException
*/
private function _validateFields()
private function _validateFields(): void
{
if (empty($this->_to)) {
throw new ValidationException('To Address is required');
@@ -265,7 +265,7 @@ class Client
*
* @throws ValidationException
*/
public function addAttachment(string $fileLocation)
public function addAttachment(string $fileLocation): void
{
if (!file_exists($fileLocation)) {
throw new ValidationException('File does not exist.');
@@ -276,7 +276,7 @@ class Client
/**
* @param \DateTimeInterface $sendTime
*/
public function sendTime(\DateTimeInterface $sendTime)
public function sendTime(\DateTimeInterface $sendTime): void
{
$this->_sendTime = $sendTime;
}

View File

@@ -3,6 +3,7 @@
namespace Siteworx\Mail\Transports;
use GuzzleHttp\Client as Guzzle;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Exception\ServerException;
use Psr\Log\LoggerInterface;
@@ -14,37 +15,37 @@ class ApiTransport implements TransportInterface
/**
* @var string
*/
private $_apiEndpoint = 'https://email.siteworxpro.com';
private string $_apiEndpoint = 'https://email.siteworxpro.com';
/**
* @var string
*/
private $_clientId = '';
private string $_clientId = '';
/**
* @var string
*/
private $_clientSecret = '';
private string $_clientSecret = '';
/**
* @var string
*/
private $_accessToken = '';
private string $_accessToken = '';
/**
* @var Guzzle
*/
private $_client;
private Guzzle $_client;
/**
* @var CacheInterface
* @var CacheInterface | null
*/
private $_cache = null;
private ?CacheInterface $_cache = null;
/**
* @var LoggerInterface
* @var LoggerInterface | null
*/
private $_logger = null;
private ?LoggerInterface $_logger = null;
/**
* Client constructor.
@@ -71,17 +72,17 @@ class ApiTransport implements TransportInterface
}
/**
* @param mixed $Cache
* @param mixed $cache
*/
public function setCache(CacheInterface $Cache)
public function setCache(CacheInterface $cache): void
{
$this->_cache = $Cache;
$this->_cache = $cache;
}
/**
* @param LoggerInterface $logger
*/
public function setLogger(LoggerInterface $logger)
public function setLogger(LoggerInterface $logger): void
{
$this->_logger = $logger;
}
@@ -97,7 +98,7 @@ class ApiTransport implements TransportInterface
/**
* @param string $clientId
*/
public function setClientId(string $clientId)
public function setClientId(string $clientId): void
{
$this->_clientId = $clientId;
}
@@ -105,16 +106,12 @@ class ApiTransport implements TransportInterface
/**
* @param string $clientSecret
*/
public function setClientSecret(string $clientSecret)
public function setClientSecret(string $clientSecret): void
{
$this->_clientSecret = $clientSecret;
}
/**
* @param array $payload
* @return \stdClass
*/
public function sentMailPayload(array $payload)
public function sentMailPayload(array $payload): \stdClass
{
$this->setToken();
@@ -139,7 +136,7 @@ class ApiTransport implements TransportInterface
$this->_logger->debug(\json_encode($body));
}
} catch (ServerException $exception) {
} catch (ServerException | RequestException | GuzzleException $exception) {
$result = $exception->getResponse();
$body = $result->getBody()->getContents();
@@ -150,19 +147,6 @@ class ApiTransport implements TransportInterface
$this->_logger->warning('An error occurred sending the email! (' . $result->getStatusCode() . ')');
$this->_logger->debug(\json_encode($body));
}
} catch (RequestException $exception) {
$result = $exception->getResponse();
$body = $result->getBody()->getContents();
$data = json_decode($body);
if ($this->_logger !== null) {
$this->_logger->warning('An error occurred sending the email! (' . $result->getStatusCode() . ')');
$this->_logger->debug(\json_encode($body));
}
}
return $data;
@@ -185,10 +169,7 @@ class ApiTransport implements TransportInterface
}
/**
* @return \stdClass
*/
private function refreshToken()
private function refreshToken(): void
{
$params = [
'scope' => 'default',
@@ -198,36 +179,32 @@ class ApiTransport implements TransportInterface
];
try {
$result = $this->_client->post($this->_apiEndpoint . '/access_token', [
'form_params' => $params
'json' => $params
]);
$body = $result->getBody()->getContents();
$data = json_decode($body);
$data = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
$this->_accessToken = $data->access_token;
if ($this->_cache !== null) {
$this->_cache->set('access_token', $this->_accessToken, $data->expires_in);
$this->_cache?->set('access_token', $this->_accessToken, $data->expires_in);
} catch (\JsonException | ServerException | RequestException | GuzzleException $exception) {
$result = $exception->getResponse();
$body = $result?->getBody()->getContents();
try {
$data = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
$this->_logger?->error($e->getMessage());
}
} catch (ServerException $exception) {
$result = $exception->getResponse();
$body = $result->getBody()->getContents();
$data = json_decode($body);
} catch (RequestException $exception) {
$result = $exception->getResponse();
$body = $result->getBody()->getContents();
$data = json_decode($body);
$this->_logger?->error($exception->getMessage() . ' ' . $data['message'] ?? '');
throw new \RuntimeException($exception);
}
return $data;
}
public function deleteEmail(string $uuid): bool