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