1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Debug\Viewer\Middleware; |
6
|
|
|
|
7
|
|
|
use Psr\Http\Message\ResponseInterface; |
8
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
9
|
|
|
use Psr\Http\Server\MiddlewareInterface; |
10
|
|
|
use Psr\Http\Server\RequestHandlerInterface; |
11
|
|
|
use Yiisoft\Assets\AssetManager; |
12
|
|
|
use Yiisoft\View\WebView; |
13
|
|
|
use Yiisoft\Yii\Debug\Viewer\Asset\DevPanelAsset; |
14
|
|
|
|
15
|
|
|
final class DevPanelMiddleware implements MiddlewareInterface |
16
|
|
|
{ |
17
|
|
|
public function __construct( |
18
|
|
|
private string $viewerUrl, |
19
|
|
|
private string $backendUrl, |
20
|
|
|
private AssetManager $assetManager, |
21
|
|
|
private WebView $view, |
22
|
|
|
) { |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @inheritDoc |
27
|
|
|
*/ |
28
|
|
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
29
|
|
|
{ |
30
|
|
|
$this->assetManager->register(DevPanelAsset::class); |
31
|
|
|
$this->view->registerJs( |
32
|
|
|
<<<JS |
33
|
|
|
const containerId = 'yii-dev-panel'; |
34
|
|
|
const container = document.createElement('div'); |
35
|
|
|
container.setAttribute('id', containerId); |
36
|
|
|
container.style.flex = "1"; |
37
|
|
|
document.body.append(container); |
38
|
|
|
|
39
|
|
|
console.log('window.YiiDevPanelWidget', window.YiiDevPanelWidget) |
40
|
|
|
window['YiiDevPanelWidget'] = window['YiiDevPanelWidget'] ?? {}; |
41
|
|
|
window['YiiDevPanelWidget'].config = { |
42
|
|
|
containerId: containerId, |
43
|
|
|
options: { |
44
|
|
|
router: { |
45
|
|
|
basename: '{$this->viewerUrl}', |
46
|
|
|
useHashRouter: false, |
47
|
|
|
}, |
48
|
|
|
backend: { |
49
|
|
|
baseUrl: '{$this->backendUrl}', |
50
|
|
|
} |
51
|
|
|
}, |
52
|
|
|
}; |
53
|
|
|
JS, |
54
|
|
|
WebView::POSITION_LOAD, |
55
|
|
|
); |
56
|
|
|
|
57
|
|
|
return $handler->handle($request); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|