0 follower

Final Class Yiisoft\Yii\Debug\Viewer\Middleware\DevPanelMiddleware

InheritanceYiisoft\Yii\Debug\Viewer\Middleware\DevPanelMiddleware
ImplementsPsr\Http\Server\MiddlewareInterface

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( string $containerId, string $viewerUrl, string $backendUrl, string $editorUrl, string $staticUrl, \Yiisoft\Assets\AssetManager $assetManager, \Yiisoft\View\WebView $view, \Yiisoft\Router\UrlGeneratorInterface $urlGenerator )
$containerId string
$viewerUrl string
$backendUrl string
$editorUrl string
$staticUrl string
$assetManager \Yiisoft\Assets\AssetManager
$view \Yiisoft\View\WebView
$urlGenerator \Yiisoft\Router\UrlGeneratorInterface

                public function __construct(
    private string $containerId,
    private string $viewerUrl,
    private string $backendUrl,
    private string $editorUrl,
    private string $staticUrl,
    private AssetManager $assetManager,
    private WebView $view,
    private UrlGeneratorInterface $urlGenerator,
) {
}

            
process() public method

public \Psr\Http\Message\ResponseInterface process ( \Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Server\RequestHandlerInterface $handler )
$request \Psr\Http\Message\ServerRequestInterface
$handler \Psr\Http\Server\RequestHandlerInterface

                public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
    $baseUriPrefix = $this->urlGenerator->getUriPrefix();
    $this->assetManager->registerCustomized(DevPanelAsset::class, ['baseUrl' => $this->staticUrl]);
    $this->view->registerJs(
        <<<JS
        (function(){
        let queryParams = {toolbar: '1'};
        try {
            queryParams = Object.fromEntries(new URLSearchParams(location.search));
        } catch (e) {
            console.error('Error while parsing query params: ', e);
        }
        const containerId = '{$this->containerId}';
        const container = document.createElement('div');
        container.setAttribute('id', containerId);
        container.style.flex = "1";
        document.body.append(container);
        window['YiiDevPanelWidget'] = window['YiiDevPanelWidget'] ?? {};
        window['YiiDevPanelWidget'].config = {
            containerId: containerId,
            options: {
                application: {
                    editorUrl: '{$this->editorUrl}',
                },
                modules: {
                    toolbar: queryParams?.toolbar !== '0',
                },
                router: {
                    basename: '{$baseUriPrefix}{$this->viewerUrl}',
                    useHashRouter: false,
                },
                backend: {
                    baseUrl: '{$this->backendUrl}{$baseUriPrefix}',
                    usePreferredUrl: true,
                }
            },
        };
        })();
        JS,
        WebView::POSITION_LOAD,
    );
    return $handler->handle($request);
}