Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
JsonContent | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
toHeader | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace PeServer\Core\Http\Client; |
6 | |
7 | use PeServer\Core\Http\HttpHeader; |
8 | use PeServer\Core\Mime; |
9 | use PeServer\Core\Serialization\JsonSerializer; |
10 | |
11 | class JsonContent extends StaticContentBase |
12 | { |
13 | /** |
14 | * 生成。 |
15 | * |
16 | * @param array<mixed>|object $value |
17 | * @param string $mime |
18 | * @param JsonSerializer|null $jsonSerializer |
19 | */ |
20 | public function __construct( |
21 | array|object $value, |
22 | private string $mime = Mime::JSON, |
23 | ?JsonSerializer $jsonSerializer = null |
24 | ) { |
25 | $jsonSerializer = $jsonSerializer ?? new JsonSerializer(); |
26 | |
27 | $body = $jsonSerializer->save($value); |
28 | parent::__construct($body); |
29 | } |
30 | |
31 | #region StaticContentBase |
32 | |
33 | public function toHeader(): HttpHeader |
34 | { |
35 | return $this->createContentTypeHeader($this->mime); |
36 | } |
37 | |
38 | #endregion |
39 | } |