Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
16 / 16 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| Http | |
100.00% |
16 / 16 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getClient | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| writeLog | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Pop PHP Framework (https://www.popphp.org/) |
| 4 | * |
| 5 | * @link https://github.com/popphp/popphp-framework |
| 6 | * @author Nick Sagona, III <dev@noladev.com> |
| 7 | * @copyright Copyright (c) 2009-2026 NOLA Interactive, LLC. |
| 8 | * @license https://www.popphp.org/license New BSD License |
| 9 | */ |
| 10 | |
| 11 | /** |
| 12 | * @namespace |
| 13 | */ |
| 14 | namespace Pop\Log\Writer; |
| 15 | |
| 16 | use Pop\Http\Client; |
| 17 | |
| 18 | /** |
| 19 | * Http log writer class |
| 20 | * |
| 21 | * @category Pop |
| 22 | * @package Pop\Log |
| 23 | * @author Nick Sagona, III <dev@noladev.com> |
| 24 | * @copyright Copyright (c) 2009-2026 NOLA Interactive, LLC. |
| 25 | * @license https://www.popphp.org/license New BSD License |
| 26 | * @version 4.0.4 |
| 27 | */ |
| 28 | class Http extends AbstractWriter |
| 29 | { |
| 30 | |
| 31 | /** |
| 32 | * Stream object |
| 33 | * @var ?Client |
| 34 | */ |
| 35 | protected ?Client $client = null; |
| 36 | |
| 37 | /** |
| 38 | * Constructor |
| 39 | * |
| 40 | * Instantiate the Mail writer object |
| 41 | * |
| 42 | * @param Client $client |
| 43 | */ |
| 44 | public function __construct(Client $client) |
| 45 | { |
| 46 | $this->client = $client; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Get client |
| 51 | * @return Client |
| 52 | */ |
| 53 | public function getClient(): Client |
| 54 | { |
| 55 | return $this->client; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Write to the log |
| 60 | * |
| 61 | * @param mixed $level |
| 62 | * @param string $message |
| 63 | * @param array $context |
| 64 | * @return Http |
| 65 | */ |
| 66 | public function writeLog(mixed $level, string $message, array $context = []): Http |
| 67 | { |
| 68 | if ($this->isWithinLogLimit($level)) { |
| 69 | $timestamp = $context['timestamp']; |
| 70 | $name = $context['name']; |
| 71 | |
| 72 | unset($context['timestamp']); |
| 73 | unset($context['name']); |
| 74 | |
| 75 | $this->client->setData([ |
| 76 | 'timestamp' => $timestamp, |
| 77 | 'level' => $level, |
| 78 | 'name' => $name, |
| 79 | 'message' => $message, |
| 80 | 'context' => $context |
| 81 | ]); |
| 82 | |
| 83 | $this->client->send(); |
| 84 | } |
| 85 | |
| 86 | return $this; |
| 87 | } |
| 88 | |
| 89 | } |