1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Debug\Api\Controller; |
6
|
|
|
|
7
|
|
|
use Psr\Http\Message\ResponseInterface; |
8
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
9
|
|
|
use Yiisoft\DataResponse\DataResponseFactoryInterface; |
10
|
|
|
use Yiisoft\Yii\Debug\Api\Repository\CollectorRepositoryInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Debug controller provides endpoints that expose information about requests processed that debugger collected. |
14
|
|
|
*/ |
15
|
|
|
class DebugController |
16
|
|
|
{ |
17
|
|
|
private DataResponseFactoryInterface $responseFactory; |
18
|
|
|
private CollectorRepositoryInterface $collectorRepository; |
19
|
|
|
|
20
|
|
|
public function __construct( |
21
|
|
|
DataResponseFactoryInterface $responseFactory, |
22
|
|
|
CollectorRepositoryInterface $collectorRepository |
23
|
|
|
) { |
24
|
|
|
$this->responseFactory = $responseFactory; |
25
|
|
|
$this->collectorRepository = $collectorRepository; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* List of requests processed. |
30
|
|
|
* |
31
|
|
|
* @return ResponseInterface |
32
|
|
|
*/ |
33
|
|
|
public function index(): ResponseInterface |
34
|
|
|
{ |
35
|
|
|
return $this->responseFactory->createResponse($this->collectorRepository->getSummary()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Summary about a processed request identified by ID specified. |
40
|
|
|
* |
41
|
|
|
* @param ServerRequestInterface $request |
42
|
|
|
* |
43
|
|
|
* @return ResponseInterface |
44
|
|
|
*/ |
45
|
|
|
public function summary(ServerRequestInterface $request): ResponseInterface |
46
|
|
|
{ |
47
|
|
|
$data = $this->collectorRepository->getSummary($request->getAttribute('id')); |
48
|
|
|
return $this->responseFactory->createResponse($data); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Detail information about a processed request identified by ID. |
53
|
|
|
* |
54
|
|
|
* @param ServerRequestInterface $request |
55
|
|
|
* |
56
|
|
|
* @return ResponseInterface response. |
57
|
|
|
*/ |
58
|
|
|
public function view(ServerRequestInterface $request): ResponseInterface |
59
|
|
|
{ |
60
|
|
|
$data = $this->collectorRepository->getDetail( |
61
|
|
|
$request->getAttribute('id') |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
return $this->responseFactory->createResponse($data); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Dump information about a processed request identified by ID. |
69
|
|
|
* |
70
|
|
|
* @param ServerRequestInterface $request |
71
|
|
|
* |
72
|
|
|
* @return ResponseInterface response. |
73
|
|
|
*/ |
74
|
|
|
public function dump(ServerRequestInterface $request): ResponseInterface |
75
|
|
|
{ |
76
|
|
|
$data = $this->collectorRepository->getDumpObject( |
77
|
|
|
$request->getAttribute('id') |
78
|
|
|
); |
79
|
|
|
|
80
|
|
|
return $this->responseFactory->createResponse($data); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Object information about a processed request identified by ID. |
85
|
|
|
* |
86
|
|
|
* @param ServerRequestInterface $request |
87
|
|
|
* |
88
|
|
|
* @return ResponseInterface response. |
89
|
|
|
*/ |
90
|
|
|
public function object(ServerRequestInterface $request): ResponseInterface |
91
|
|
|
{ |
92
|
|
|
$data = $this->collectorRepository->getObject( |
93
|
|
|
$request->getAttribute('id'), |
94
|
|
|
$request->getAttribute('objectId') |
95
|
|
|
); |
96
|
|
|
|
97
|
|
|
return $this->responseFactory->createResponse($data); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|