0 follower

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

InheritanceYiisoft\Yii\Debug\Viewer\Middleware\ToolbarMiddleware
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(ToolbarAsset::class, ['baseUrl' => $this->staticUrl]);
    $this->view->registerJs(
        <<<JS
        (function(){
        const containerId = '{$this->containerId}';
        const container = document.createElement('div');
        container.setAttribute('id', containerId);
        container.style.flex = "0";
        document.body.append(container);
        window['YiiDevPanelToolbarWidget'] = window['YiiDevPanelToolbarWidget'] ?? {};
        window['YiiDevPanelToolbarWidget'].config = {
            containerId: containerId,
            options: {
                application: {
                    editorUrl: '{$this->editorUrl}',
                },
                modules: {
                     toolbar: '1',
                 },
                router: {
                    basename: '{$baseUriPrefix}',
                    useHashRouter: false,
                },
                backend: {
                    baseUrl: '{$this->backendUrl}{$baseUriPrefix}',
                    usePreferredUrl: true,
                }
            },
        };
        })();
        JS,
        WebView::POSITION_LOAD,
    );
    return $handler->handle($request);
}