Skip to content

Latest commit

 

History

History
104 lines (74 loc) · 5.34 KB

File metadata and controls

104 lines (74 loc) · 5.34 KB

Vite diagnostics

PSR-14, and nothing else

Vite emits PHPForge\Vite\Event\AssetsResolved through an optional Psr\EventDispatcher\EventDispatcherInterface. The application classes never import a debug contract or call a collector, and installing the contracts does not activate a debugger.

The event carries the configuration, the actual per-call entrypoints, the returned assets, and the manifest a successful resolver already used. The collector never loads a manifest or runs an inline provider. Each successful resolution becomes a component row; repeated calls are recorded in order, not deduplicated into one. Failed resolutions do not invent completion events.

Development wiring

The package ships one collector and one panel, PHPForge\Vite\Debug\ViteCollector and PHPForge\Vite\Debug\VitePanel; the host never reimplements collection or presentation. In any framework: pass ViteCollector as the eventDispatcher of Vite::create() or register it as a listener of AssetsResolved on your dispatcher, and register the collector and VitePanel with your debugger under the ID vite. The debuggers name no provider package, so nothing is wired until the application declares it.

Yii3, three entries in the application configuration

yii3/debug reads collectors and panels from its params and resolves the collector from the container, the same instance the event dispatcher calls. The container autowires Psr\EventDispatcher\EventDispatcherInterface into Vite, and ViteCollector has no constructor, so it needs no definition:

use PHPForge\Vite\Debug\{ViteCollector, VitePanel};
use PHPForge\Vite\Event\AssetsResolved;

// config/params.php
'yii3/debug' => [
    'collectors' => ['vite' => ViteCollector::class],
    'panels' => ['vite' => VitePanel::class],
],

// config/events-web.php
AssetsResolved::class => [ViteCollector::class],

Without yii3/debug installed the params entry is inert and the listener only buffers.

Yii2, one module registration

Yii2 has no framework-native PSR-14 dispatcher. Vite emits exactly one event type, so ViteCollector is its own single-listener dispatcher, and the module's dispatchers option hands it to the component that resolves the assets. Inside the existing YII_DEBUG configuration guard:

use PHPForge\Vite\Debug\{ViteCollector, VitePanel};

$config['modules']['debug']['collectors']['vite'] = ViteCollector::class;
$config['modules']['debug']['panels']['vite'] = VitePanel::class;
// Collector ID => the component ID the application already uses for `PHPForge\Vite\Vite`.
$config['modules']['debug']['dispatchers']['vite'] = 'vite';

The module writes the collector into the eventDispatcher constructor argument of the component definition before the request runs, without instantiating it; a component instantiated earlier is rejected with an explicit error. A dispatcher the definition already configures is kept: if the application owns a real PSR-14 dispatcher, register the collector as a listener on it and leave vite out of dispatchers; never replace a populated dispatcher with an empty one.

The debugger groups the panel under Extensions. Disable it with 'enabled' => false on both entries; removing php-forge/vite while the configuration still names its classes fails with an error naming the class.

Inject the dispatcher into the actual Vite service, not into a duplicate diagnostic-only one. Omitting it is safe: resolution behaves normally and the panel simply stays empty.

Lifecycle and errors

Register the collector once and let the host drive it. startup() enables the listener without discarding current observations if called twice; shutdown() disables it and clears references. Events outside that window are ignored.

An active but unused collector captures ['components' => []]; disabled collection captures null.

Attach the event only to trusted listeners: it carries real application data, so never point an unrestricted event dumper at it. Listener exceptions propagate per PSR-14; they are never swallowed and never retried. The supplied listener only buffers the event.

Compatibility

Hosts previously shipped their own Vite collector and panel; both were removed, so the vite ID is free for the provider-owned objects an application registers itself. An extension now declares its own ID, icon and title. Captures written by the removed host collector still render, because the payload shape is unchanged.

eventDispatcher is an optional trailing argument: calls without one behave normally and emit no events. The branch aliases still describe an unreleased linked prototype, not a published release.

How this is verified

  • The full PHPUnit suite runs through this package's own autoloader, without Debug Core installed.
  • python3 tools/check-provider-consumer.py (in php-forge/debug) exports the package and its locked production dependencies into a temporary mirror, installs with Packagist and plugins disabled, then exercises real resolution, cleanup and replay with no debugger or framework present.
  • DEBUG_UI_SEED_FIXTURES=0 npx playwright test e2e/provider-events.spec.js (in Debug Core) checks persisted values after a changed request, including an empty Vite capture, accessibility, and both themes and viewport sizes.

Reference: PSR-14.


← Back to documentation