|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Debug\Viewer; |
|
6
|
|
|
|
|
7
|
|
|
use Psr\Http\Message\ResponseFactoryInterface; |
|
8
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
9
|
|
|
use Yiisoft\DataResponse\DataResponseFactoryInterface; |
|
10
|
|
|
use Yiisoft\Router\CurrentRoute; |
|
11
|
|
|
use Yiisoft\Yii\Debug\Viewer\Panels\PanelInterface; |
|
12
|
|
|
|
|
13
|
|
|
final class IndexController |
|
14
|
|
|
{ |
|
15
|
|
|
private DataResponseFactoryInterface $responseFactory; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* IndexController constructor. |
|
19
|
|
|
*/ |
|
20
|
|
|
public function __construct( |
|
21
|
|
|
DataResponseFactoryInterface $responseFactory |
|
22
|
|
|
) { |
|
23
|
|
|
$this->responseFactory = $responseFactory; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @return ResponseInterface |
|
28
|
|
|
*/ |
|
29
|
|
|
public function index(): ResponseInterface |
|
30
|
|
|
{ |
|
31
|
|
|
return $this->responseFactory->createResponse( |
|
32
|
|
|
file_get_contents(dirname(__DIR__) . '/resources/views/index.html') |
|
33
|
|
|
); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function panel(CurrentRoute $currentRoute, PanelCollection $panelCollection): ResponseInterface |
|
37
|
|
|
{ |
|
38
|
|
|
$panel = $panelCollection->getPanel($currentRoute->getArgument('panel')); |
|
|
|
|
|
|
39
|
|
|
return $this->responseFactory->createResponse($panel->renderDetail()); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function toolbar( |
|
43
|
|
|
ResponseFactoryInterface $responseFactory, |
|
44
|
|
|
PanelCollection $panelCollection |
|
45
|
|
|
) { |
|
46
|
|
|
$html = file_get_contents(dirname(__DIR__) . '/resources/views/toolbar.html'); |
|
47
|
|
|
$panels = array_map( |
|
48
|
|
|
static fn (PanelInterface $panel) => $panel->renderSummary(), |
|
49
|
|
|
$panelCollection->getPanels() |
|
50
|
|
|
); |
|
51
|
|
|
$html = strtr($html, ['{TOOLBAR_BLOCKS}' => implode("\n", $panels)]); |
|
52
|
|
|
$response = $responseFactory->createResponse() |
|
53
|
|
|
->withHeader('Content-Type', 'text/html'); |
|
54
|
|
|
$response->getBody()->write($html); |
|
55
|
|
|
return $response; |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|