Skip to content

Yii 3 Adapter

The Yii 3 adapter is the reference ADP adapter. It bridges ADP Kernel and API into Yii 3 via config plugins.

Installation

bash
composer require app-dev-panel/adapter-yii3

The config plugin system wires DI, event listeners, and collectors automatically. One piece the plugin cannot set for you is the middleware stack — Yii 3's config/web/di/application.php is owned by the application, so the three ADP middleware have to be added there by hand (see Middleware below).

Configuration

All settings are managed in config/params.php:

php
'app-dev-panel/yii3' => [
    'enabled' => true,
    'collectors' => [...],
    'trackedServices' => [...],
    'ignoredRequests' => [],
    'ignoredCommands' => [],
    'dumper' => [
        'excludedClasses' => [],
    ],
    'logLevel' => [
        'AppDevPanel\\' => 0,
    ],
    'storage' => [
        'path' => '@runtime/debug',
        'historySize' => 50,
        'exclude' => [],
    ],
],

Middleware

Three middleware have to be added to config/web/di/application.php. Order matters — the adapter assumes this stack:

ToolbarMiddleware → ErrorCatcher → YiiApiMiddleware → SessionMiddleware → CsrfTokenMiddleware → RequestCatcherMiddleware → Router
MiddlewarePurpose
ToolbarMiddlewareAppDevPanel\Adapter\Yii3\Api\ToolbarMiddlewareInjects the ADP debug toolbar into HTML responses, just before </body>. Must be outermost so it can rewrite the body produced by any downstream middleware (including error pages).
YiiApiMiddlewareAppDevPanel\Adapter\Yii3\Api\YiiApiMiddlewarePSR-15 middleware that intercepts /debug/api and /inspect/api requests and delegates them to the ADP ApiApplication.final Adapter/Yii3 · class · implements MiddlewareInterfaceIntercepts /debug/* (panel SPA + /debug/api/*) and /inspect/api/* and delegates them to the ADP API application. Must be before Router so the user's routes don't shadow ADP's, and after ErrorCatcher so exceptions bubble up through Yii's error pipeline. Static panel assets are served by the web server directly from the public directory the adapter symlinks into (@public/app-dev-panel), not by this middleware.

Copy-paste-ready config/web/di/application.php for the stock yiisoft/app template:

php
<?php

declare(strict_types=1);

use App\Web\NotFound\NotFoundHandler;
use AppDevPanel\Adapter\Yii3\Api\ToolbarMiddleware;
use AppDevPanel\Adapter\Yii3\Api\YiiApiMiddleware;
use Yiisoft\Csrf\CsrfTokenMiddleware;
use Yiisoft\Definitions\DynamicReference;
use Yiisoft\Definitions\Reference;
use Yiisoft\ErrorHandler\Middleware\ErrorCatcher;
use Yiisoft\Middleware\Dispatcher\MiddlewareDispatcher;
use Yiisoft\RequestProvider\RequestCatcherMiddleware;
use Yiisoft\Router\Middleware\Router;
use Yiisoft\Session\SessionMiddleware;
use Yiisoft\Yii\Http\Application;

return [
    Application::class => [
        '__construct()' => [
            'dispatcher' => DynamicReference::to([
                'class' => MiddlewareDispatcher::class,
                'withMiddlewares()' => [
                    [
                        ToolbarMiddleware::class,
                        ErrorCatcher::class,
                        YiiApiMiddleware::class,
                        SessionMiddleware::class,
                        CsrfTokenMiddleware::class,
                        RequestCatcherMiddleware::class,
                        Router::class,
                    ],
                ],
            ]),
            'fallbackHandler' => Reference::to(NotFoundHandler::class),
        ],
    ],
];

Middleware Order

YiiApiMiddleware must be placed before the Router middleware but after ErrorCatcher. If placed after the router, ADP routes will not be intercepted. If placed before error handling, exceptions in ADP itself won't be caught gracefully. ToolbarMiddleware must be outermost — it rewrites the HTML body returned by everything below it.

Collectors

Includes Yii-specific collectors for database queries, mailer, queue, router, validator, translator, and views — in addition to all Kernel collectors (logs, events, exceptions, HTTP client, etc.).

Additionally:

Translator Integration

When yiisoft/translator is installed, the adapter registers TranslatorInterfaceProxyAppDevPanel\Adapter\Yii3\Collector\Translator\TranslatorInterfaceProxyDecorates Yiisoft TranslatorInterface to feed translation lookups to TranslatorCollector.final Adapter/Yii3 · class · implements TranslatorInterface in trackedServices. All translate() calls on Yiisoft\Translator\TranslatorInterface are intercepted automatically. See Translator for details.

Database Inspector

Database schema inspection is provided via Yiisoft\Db through DbSchemaProviderAppDevPanel\Adapter\Yii3\Inspector\DbSchemaProviderProvides Db Schema data.Adapter/Yii3 · class · implements SchemaProviderInterface.

Released under the MIT License.