1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
7
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
8
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
9
|
|
|
* |
10
|
|
|
* Copyright (c) 2024 Mykhailo Shtanko [email protected] |
11
|
|
|
* |
12
|
|
|
* For the full copyright and license information, please view the LICENSE.MD |
13
|
|
|
* file that was distributed with this source code. |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace FRZB\Component\MetricsPower\Logger\Traits; |
17
|
|
|
|
18
|
|
|
use FRZB\Component\MetricsPower\Attribute\OptionsInterface; |
19
|
|
|
use FRZB\Component\MetricsPower\Helper\ClassHelper; |
20
|
|
|
use FRZB\Component\MetricsPower\Logger\Data\Context; |
21
|
|
|
use Symfony\Component\Serializer\Encoder\JsonEncoder; |
22
|
|
|
use Symfony\Component\Serializer\SerializerInterface; |
23
|
|
|
|
24
|
|
|
trait CanExtractContext |
25
|
|
|
{ |
26
|
|
|
public function __construct( |
27
|
|
|
private readonly SerializerInterface $serializer, |
28
|
|
|
) {} |
29
|
|
|
|
30
|
|
|
public function extract(mixed $target, ?OptionsInterface $options = null, ?\Throwable $exception = null): Context |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
$context = [ |
33
|
|
|
'target_class' => ClassHelper::getShortName($target), |
34
|
|
|
'message_class' => ClassHelper::getShortName($target->getEnvelope()->getMessage()), |
35
|
|
|
]; |
36
|
|
|
|
37
|
|
|
if ($options?->isSerializable()) { |
38
|
|
|
$context += ['message_values' => $this->serializer->serialize($target->getEnvelope()->getMessage(), JsonEncoder::FORMAT)]; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
if ($options) { |
42
|
|
|
$context += [ |
43
|
|
|
'options_class' => ClassHelper::getShortName($options), |
44
|
|
|
]; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return new Context(self::MESSAGE, $context); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.