1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace BEAR\Resource\SemanticLog; |
6
|
|
|
|
7
|
|
|
use BEAR\Resource\AbstractRequest; |
8
|
|
|
use BEAR\Resource\InvokerInterface; |
9
|
|
|
use BEAR\Resource\ResourceObject; |
10
|
|
|
use Koriym\SemanticLogger\SemanticLoggerInterface; |
|
|
|
|
11
|
|
|
use Override; |
12
|
|
|
use Ray\Di\Di\Named; |
13
|
|
|
use Throwable; |
14
|
|
|
|
15
|
|
|
use function array_merge; |
16
|
|
|
use function get_class; |
17
|
|
|
use function is_array; |
18
|
|
|
use function property_exists; |
19
|
|
|
use function strtolower; |
20
|
|
|
use function ucfirst; |
21
|
|
|
|
22
|
|
|
final class SemanticResourceInvokerAdapter implements InvokerInterface |
23
|
|
|
{ |
24
|
|
|
public function __construct( |
25
|
|
|
#[Named('Original')] |
26
|
|
|
private InvokerInterface $invoker, |
27
|
|
|
private SemanticLoggerInterface $semanticLogger, |
28
|
|
|
) { |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
#[Override] |
32
|
|
|
public function invoke(AbstractRequest $request): ResourceObject |
33
|
|
|
{ |
34
|
|
|
// Use resource class name for better traceability |
35
|
|
|
$resourceClass = get_class($request->resourceObject); |
36
|
|
|
|
37
|
|
|
// Convert HTTP method to resource method (GET -> onGet) |
38
|
|
|
$resourceMethod = 'on' . ucfirst(strtolower($request->method)); |
39
|
|
|
|
40
|
|
|
// Combine query and body parameters for complete parameter context |
41
|
|
|
$parameters = array_merge( |
42
|
|
|
$request->query, |
43
|
|
|
property_exists($request, 'body') && is_array($request->body) ? $request->body : [], |
44
|
|
|
); |
45
|
|
|
|
46
|
|
|
/** @var array<string, mixed> $parameters */ |
47
|
|
|
$context = new ResourceOpenContext( |
48
|
|
|
$resourceClass, |
49
|
|
|
$resourceMethod, |
50
|
|
|
$parameters, |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
$openId = $this->semanticLogger->open($context); |
54
|
|
|
|
55
|
|
|
try { |
56
|
|
|
$result = $this->invoker->invoke($request); |
57
|
|
|
|
58
|
|
|
$closeContext = new ResourceCompleteContext( |
59
|
|
|
$resourceClass, |
60
|
|
|
$resourceMethod, |
61
|
|
|
$result->code, |
62
|
|
|
/** @var array<string, mixed> */ |
63
|
|
|
(array) $result->body, |
64
|
|
|
); |
65
|
|
|
|
66
|
|
|
$this->semanticLogger->close($closeContext, $openId); |
67
|
|
|
|
68
|
|
|
return $result; |
69
|
|
|
} catch (Throwable $e) { |
70
|
|
|
$errorContext = new ResourceErrorContext( |
71
|
|
|
$resourceClass, |
72
|
|
|
$resourceMethod, |
73
|
|
|
$e::class, |
74
|
|
|
$e->getMessage(), |
75
|
|
|
); |
76
|
|
|
|
77
|
|
|
$this->semanticLogger->close($errorContext, $openId); |
78
|
|
|
|
79
|
|
|
throw $e; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths