Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
15 / 15 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| AbstractHttp | |
100.00% |
15 / 15 |
|
100.00% |
5 / 5 |
11 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| setClient | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getClient | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasClient | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| parseOptions | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
6 | |||
| createClient | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | /** |
| 4 | * Pop PHP Framework (https://www.popphp.org/) |
| 5 | * |
| 6 | * @link https://github.com/popphp/popphp-framework |
| 7 | * @author Nick Sagona, III <dev@noladev.com> |
| 8 | * @copyright Copyright (c) 2009-2027 NOLA Interactive, LLC. |
| 9 | * @license https://www.popphp.org/license New BSD License |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * @namespace |
| 14 | */ |
| 15 | namespace Pop\Mail\Api; |
| 16 | |
| 17 | use Pop\Http; |
| 18 | use Aws\Ses\SesClient; |
| 19 | |
| 20 | /** |
| 21 | * Abstract HTTP base class |
| 22 | * |
| 23 | * @category Pop |
| 24 | * @package Pop\Mail |
| 25 | * @author Nick Sagona, III <dev@noladev.com> |
| 26 | * @copyright Copyright (c) 2009-2027 NOLA Interactive, LLC. |
| 27 | * @license https://www.popphp.org/license New BSD License |
| 28 | * @version 5.0.0 |
| 29 | */ |
| 30 | abstract class AbstractHttp implements HttpInterface |
| 31 | { |
| 32 | |
| 33 | /** |
| 34 | * Client |
| 35 | * @var mixed |
| 36 | */ |
| 37 | protected mixed $client = null; |
| 38 | |
| 39 | /** |
| 40 | * Create Office 365 object |
| 41 | * |
| 42 | * @param array|string|null $options |
| 43 | */ |
| 44 | public function __construct(array|string|null $options = null) |
| 45 | { |
| 46 | if ($options !== null) { |
| 47 | $this->createClient($options); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Set client |
| 53 | * |
| 54 | * @param mixed $client |
| 55 | * @return AbstractHttp |
| 56 | */ |
| 57 | public function setClient(mixed $client): AbstractHttp |
| 58 | { |
| 59 | $this->client = $client; |
| 60 | return $this; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Get client |
| 65 | * |
| 66 | * @return mixed |
| 67 | */ |
| 68 | public function getClient(): mixed |
| 69 | { |
| 70 | return $this->client; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Has client |
| 75 | * |
| 76 | * @return bool |
| 77 | */ |
| 78 | public function hasClient(): bool |
| 79 | { |
| 80 | return ($this->client !== null); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Parse options |
| 85 | * |
| 86 | * @param array|string $options |
| 87 | * @throws Exception |
| 88 | * @return array |
| 89 | */ |
| 90 | public function parseOptions(array|string $options): array |
| 91 | { |
| 92 | if (is_string($options)) { |
| 93 | $jsonValue = @json_decode($options, true); |
| 94 | if ((json_last_error() === JSON_ERROR_NONE) && is_array($jsonValue)) { |
| 95 | $options = $jsonValue; |
| 96 | } else if (file_exists($options)) { |
| 97 | $options = @json_decode(file_get_contents($options), true); |
| 98 | } |
| 99 | |
| 100 | if (!is_array($options)) { |
| 101 | throw new Exception('Error: Unable to parse the options.'); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | return $options; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Create client |
| 110 | * |
| 111 | * @param array|string $options |
| 112 | * @return AbstractHttp |
| 113 | */ |
| 114 | abstract public function createClient(array|string $options): AbstractHttp; |
| 115 | |
| 116 | } |