Skip to content
PHP Ecosystem
Explore

Module

API reference › Debug › Module

Bootstraps the debug toolbar and the full-page debugger over the active application.

Attaches a LogTarget to capture per-request data, registers URL rules for the debugger routes, wires the toolbar/exception-page injection listeners, and registers the collectors and panels declared in $collectors and $panels (merged on top of the built-in core definitions).

Registration itself is delegated to the services under yii\debug\service, which the module resolves through its own service locator. An application replaces one by registering a definition under the service class name: a class name, a configuration array carrying class, a callable, or a ready-made instance. Every definition but an instance is built with this module bound to the module argument, so a replacement declaring Module $module receives it.

The definition must be in place before the module resolves the service. CapturePolicyFactory, CollectorRegistrar, PanelRegistrar, and StandaloneActionResolver are resolved during init() and LogTargetFactory during bootstrap(), so replacing those requires the module components configuration; the remaining services may also be replaced later through ServiceLocator::set().

PropertyTypeDescriptionDefined by
$actionMaparray<string, class-string|array<string, mixed>>Mapping from action IDs to standalone Action class configurations. Default: []. Available since 22.0.yii\base\Module
$actionNamespacestring|nullThe namespace where standalone Action subclasses are located for convention-based discovery, parallel to $controllerNamespace for controllers. Default: null. Available since 22.0.yii\base\Module
$aliases write-onlyarrayList of path aliases to be defined.yii\base\Module
$allowedHostslist<string>Hosts allowed to access this module. Each entry is resolved to an IP at runtime; useful for dynamic DNS. Default: [].Module
$allowedIPslist<string>IPs allowed to access this module. Entries may be exact, wildcard (192.168.0.*) or CIDR (172.16.0.0/12). Default: ['127.0.0.1', '::1'].Module
$authManagerarray<string, mixed>|yii\rbac\BaseManager|stringRBAC access checker component id or fully configured manager. Default: 'authManager'.Module
$basePathstringThe root directory of the module.yii\base\Module
$behaviors read-onlyarray<yii\base\Behavior<static>>List of behaviors attached to this component.yii\base\Component
$checkAccessCallbackcallable(yii\base\Action|null): bool|nullCallback evaluated by checkAccess(). Receives the current Action (or null) and must return true to grant access. Default: null.Module
$collectorCoordinator read-onlyPHPForge\Debug\Collector\CollectorCoordinatorConfigured collector coordinator.Module
$collectorsarray<array-key, array<string, mixed>|Closure(CapturePolicy): CollectorInterface|CollectorInterface|string>Debug collectors resolved from instances, class names, Yii configuration arrays, or Closure factories during init(). Default: [].Module
$componentsarrayThe list of the component definitions or the loaded component instances (ID => definition or instance).yii\di\ServiceLocator
$controllerMaparrayMapping from controller ID to controller configurations. Default: [].yii\base\Module
$controllerNamespacestring|nullThe namespace that controller classes are in. Default: null.yii\base\Module
$controllerPathstringThe directory that contains the controller classes.yii\base\Module
$dataPathstringDirectory storing the debugger data files (path alias accepted). Default: '@runtime/debug'.Module
$debugHeaders write-onlyyii\base\EventResponse event raised after the action ran.Module
$defaultHeightintDebug bar default height, as a percentage of the total screen height. Default: 50.Module
$defaultPanelstringName of the panel that should be visible when opening the debug panel. Default: 'log'.Module
$defaultRouteRoute dispatched when the module is requested without an action segment. Default: 'index'.Module
$dirModeintPermission applied to newly created debugger directories (used by chmod()); no umask is applied. Default: 0700.Module
$disableCallbackRestrictionWarningboolWhether to disable the access-callback restriction warning emitted by checkAccess(). Default: false.Module
$disableIpRestrictionWarningboolWhether to disable the IP restriction warning emitted by checkAccess(). Default: false.Module
$dispatchersarray<string, string>Collector IDs to hand to application components as their PSR-14 dispatcher, collectorId => componentId. Default: [].Module
$enableDebugLogsboolWhether to keep log messages emitted by debug-module requests. Enable only when debugging the module itself. Default: false.Module
$fileModeint|nullPermission applied to newly created debugger data files (used by chmod()). Default: 0600.Module
$historySizeintMaximum number of debug data files to keep; older snapshots beyond this count are pruned. Default: 50.Module
$idstringAn ID that uniquely identifies this module among other modules which have the same parent. Default: null.yii\base\Module
$layoutstring|bool|nullThe layout that should be applied for views within this module. Default: null.yii\base\Module
$layoutPathstringThe root directory of layout files.yii\base\Module
$logTargetarray<string, mixed>|LogTarget|stringLogTarget instance, configuration array, or class name. Always coerced to a LogTarget by bootstrap(). Default: 'yii\debug\LogTarget'.Module
$maxBodyBytesintMaximum raw request or response body bytes retained by the shared capture policy. Default: \PHPForge\Debug\Capture\CapturePolicy::DEFAULT_MAX_BODY_BYTES.Module
$moduleyii\base\Module|nullThe parent module of this module. null if this module does not have a parent. Default: null.yii\base\Module
$modulesarrayThe modules (indexed by their IDs).yii\base\Module
$pageTitlecallable(string): string|string|nullPage title literal string or a callable receiving the base URL and returning a string. Default: null.Module
$panelRegistry read-onlyPanelRegistryResolved panel catalog.Module
$panelsarray<string, Panel>Debug panels indexed by panel id. May be populated with config arrays / class names before initPanels() runs, but after initialization the array holds only Panel instances. Default: [].Module
$paramsarrayCustom module parameters (name => value). Default: [].yii\base\Module
$sensitiveKeyPatternslist<string>|nullPCRE patterns applied to complete data keys. null enables Debug Core defaults when the default exact-key list is active; [] explicitly disables pattern matching. Default: null.Module
$sensitiveKeyPrefixeslist<string>Literal, case-insensitive data-key prefixes redacted from every persistent debugger capture. Default: [].Module
$sensitiveKeyslist<string>Exact, case-insensitive data keys redacted from every persistent debugger capture. Default: \PHPForge\Debug\Helper\SensitiveDataRedactor::DEFAULT_KEYS.Module
$shellContextFactory read-onlyyii\debug\service\ShellContextFactoryResolved shell factory.Module
$skipAjaxRequestUrlarray<int|string, mixed>Routes whose AJAX hits should NOT appear in the toolbar history (e.g. polling endpoints). Default: [].Module
$toolbarHtml read-onlystringRendered <yii-debug-toolbar> element.Module
$toolbarPositionstringToolbar position on the page ('bottom' or 'upper'). Default: 'bottom'.Module
$traceLinecallable(array<string, mixed>, Panel): string|false|stringTrace-line template placeholder string ({file}, {line}, {text}), callable returning the rendered line, or false to disable trace-line rendering entirely. Default: self::DEFAULT_IDE_TRACELINE.Module
$tracePathMappingsarray<string, string>Maps containerized/remote paths to local paths for the {file} portion of $traceLine; only the first match is applied. Default: [].Module
$uniqueId read-onlystringThe unique ID of the module.yii\base\Module
$urlRuleClassstringClass name of the UrlRule used for rules generated by this module. Default: 'yii\web\UrlRule'.Module
$versionstring|callable|nullThe version of this module.yii\base\Module
$viewPathstringPath containing the framework-neutral Debug Core templates. Default: '@vendor/php-forge/debug-core/resources/views'.Module
MethodDescriptionDefined by
__construct()Constructor.yii\base\Module
__call()Calls the named method which is not a class method.yii\base\Component
__clone()This method is called after the object is created by cloning an existing one.yii\base\Component
__get()Getter magic method.yii\di\ServiceLocator
__isset()Checks if a property value is null.yii\di\ServiceLocator
__set()Sets the value of a component property.yii\base\Component
__unset()Sets a component property to be null.yii\base\Component
afterAction()This method is invoked right after an action within this module is executed.yii\base\Module
attachBehavior()Attaches a behavior to this component.yii\base\Component
attachBehaviors()Attaches a list of behaviors to the component.yii\base\Component
beforeAction()Disables the application log targets when $enableDebugLogs is false, applies the access check, and detaches the toolbar/header listeners so the debugger response is not polluted with self-debug data.Module
behaviors()Returns a list of behaviors that this component should behave as.yii\base\Component
bootstrap()Wires the debug log target, the toolbar/header listeners, the error-page injection hook, and the debugger URL rules onto the application.Module
canGetProperty()Returns a value indicating whether a property can be read.yii\base\Component
canSetProperty()Returns a value indicating whether a property can be set.yii\base\Component
className() staticReturns the fully qualified name of this class.yii\base\BaseObject
clear()Removes the component from the locator.yii\di\ServiceLocator
createCapturePolicy()Creates the shared persistent-data policy, optionally extending its exact-key list for one collector.Module
createController()Creates a controller instance based on the given route.yii\base\Module
createControllerByID()Creates a controller based on the given controller ID.yii\base\Module
detachBehavior()Detaches a behavior from the component.yii\base\Component
detachBehaviors()Detaches all behaviors from the component.yii\base\Component
ensureBehaviors()Makes sure that the behaviors declared in behaviors() are attached to this component.yii\base\Component
get()Returns the component instance with the specified ID.yii\base\Module
getBasePath()Returns the root directory of the module.yii\base\Module
getBehavior()Returns the named behavior object.yii\base\Component
getBehaviors()Returns all behaviors attached to this component.yii\base\Component
getCollectorCoordinator()Returns the validated collector coordinator used by the request log target.Module
getComponents()Returns the list of the component definitions or the loaded component instances.yii\di\ServiceLocator
getControllerPath()Returns the directory that contains the controller classes according to $controllerNamespace.yii\base\Module
getInstance() staticReturns the currently requested instance of this module class.yii\base\Module
getLayoutPath()Returns the directory that contains layout view files for this module.yii\base\Module
getLogTarget()Returns the initialized LogTarget, raising when the module has not been bootstrapped.Module
getModule()Retrieves the child module of the specified ID.yii\base\Module
getModules()Returns the sub-modules in this module.yii\base\Module
getPanelRegistry()Returns the effective panel catalog, which carries the display order and the IDs disabled by configuration.Module
getShellContextFactory()Returns the factory building the page shell of every debugger action.Module
getToolbarHtml()Returns the toolbar HTML: a <yii-debug-toolbar> custom element wired with data attributes the bundled JS reads.Module
getUniqueId()Returns an ID that uniquely identifies this module among all modules within the current application.yii\base\Module
getVersion()Returns current module version.yii\base\Module
getViewPath()Returns the directory that contains the view files for this module.yii\base\Module
getYiiLogo() staticReturns the Yii logo as a data URI ready to drop into <img src="…"> or <link rel="icon">.Module
has()Returns a value indicating whether the locator has the specified component definition or has instantiated the component.yii\base\Module
hasEventHandlers()Returns a value indicating whether there is any handler attached to the named event.yii\base\Component
hasMethod()Returns a value indicating whether a method is defined.yii\base\Component
hasModule()Checks whether the child module of the specified ID exists.yii\base\Module
hasProperty()Returns a value indicating whether a property is defined for this component.yii\base\Component
htmlTitle()Resolves the page title used in the debugger HTML: the literal $pageTitle string when set, the result of the configured callable, or the default Yii Debugger label.Module
init()Resolves the $dataPath alias and instantiates every configured panel.Module
injectToolbarOnErrorPage()Injects the debug toolbar into the rendered HTML of an error page (yiisoft/yii2#7616).Module
off()Detaches an existing event handler from this component.yii\base\Component
on()Attaches an event handler to an event.yii\base\Component
renderToolbar()Renders the mini-toolbar at the end of the page body.Module
route() staticBuilds a module-absolute route array for the given debugger action.Module
runAction()Runs a controller action specified by a route.yii\base\Module
set()Registers a component definition with this locator.yii\di\ServiceLocator
setAliases()Defines path aliases.yii\base\Module
setBasePath()Sets the root directory of the module.yii\base\Module
setComponents()Registers a set of component definitions in this locator.yii\di\ServiceLocator
setControllerPath()Sets the directory that contains the controller classes.yii\base\Module
setDebugHeaders()Sets headers carrying debug data on AJAX responses so the toolbar can resolve the captured tag and link back to the full view.Module
setInstance() staticSets the currently requested instance of this module class.yii\base\Module
setLayoutPath()Sets the directory that contains the layout files.yii\base\Module
setModule()Adds a sub-module to this module.yii\base\Module
setModules()Registers sub-modules in the current module.yii\base\Module
setVersion()Sets current module version.yii\base\Module
setViewPath()Sets the directory that contains the view files.yii\base\Module
setYiiLogo() staticSets the logo data URI returned by getYiiLogo().Module
trigger()Triggers an event.yii\base\Component
checkAccess() protectedReturns whether the current request is allowed to access the debugger.Module
coreActionMap() protectedBuilt-in standalone actions dispatched through Module::$actionMap, keyed by action ID.Module
coreCollectors() protectedBuilt-in collectors paired by stable ID with their presentation panels.Module
corePanels() protectedReturns the built-in panel configurations, ordered as the request itself unfolds.Module
createStandaloneAction() protectedResolves a debugger endpoint from Module::$actionMap before falling back to convention-based discovery.Module
defaultVersion() protectedReturns the default module version string.Module
initActionMap() protectedHands the built-in, panel-declared, and configured standalone actions to StandaloneActionResolver and stores the merged map on Module::$actionMap.Module
initCollectors() protectedHands the built-in and configured collector definitions to CollectorRegistrar and stores the resolved collectors with the coordinator driving them.Module
initPanels() protectedHands the built-in and configured panel definitions to PanelRegistrar and stores the resolved panels with the catalog describing their display order.Module
initPanelServices() protectedRegisters every enabled panel in the module service locator under its own class and each ancestor class below Panel.Module
resetGlobalSettings() protectedResets application-wide settings the debugger should not inherit from the host application (currently the asset bundles registry).Module
runMappedAction() protectedRuns a standalone action registered in $actionMap.yii\base\Module
runStandaloneAction() protectedRuns a standalone Action instance through the standard module/action event lifecycle.yii\base\Module
setDebuggerResponseHeaders() protectedApplies the debugger response hardening policy.Module
EventTypeDescriptionDefined by
EVENT_BEFORE_ACTIONyii\base\ActionEventAn event raised before executing a controller action. Event name: 'beforeAction'.yii\base\Module
EVENT_AFTER_ACTIONyii\base\ActionEventAn event raised after executing a controller action. Event name: 'afterAction'.yii\base\Module
ConstantValueDescriptionDefined by
DEFAULT_IDE_TRACELINE\PHPForge\Debug\Helper\Trace::DEFAULT_TEMPLATEDefault $traceLine template: the shared ide:// deep link that IDE extensions resolve into “open file at line”.Module
SOURCE_PATH'@vendor/php-forge/debug-core/resources/assets'Default source path for the framework-neutral Debug Core assets. The framework adapter may override this to provide a different path.Module
VIEW_PATH_ALIAS'@yiiDebugViews'Adapter-owned alias for the shared Debug Core templates.Module
public array<array-key, array<string, mixed>|Closure(PHPForge\Debug\Capture\CapturePolicy): PHPForge\Debug\CollectorInterface|PHPForge\Debug\CollectorInterface|string> $collectors = []

Debug collectors resolved from instances, class names, Yii configuration arrays, or Closure factories during init().

Collectors derive their own IDs; register them as a list or under a key that matches CollectorInterface::id(). A Closure receives the module CapturePolicy, so a collector capturing user data redacts it with the rules the Request panel applies. After initialization, this property holds a list of resolved instances in registration order.

public array<string, string> $dispatchers = []

Collector IDs to hand to application components as their PSR-14 dispatcher, collectorId => componentId.

The component takes the collector on a public eventDispatcher property or on a constructor parameter named eventDispatcher; an already instantiated component only accepts the property form. A dispatcher the component already configures is kept, and a collector disabled through enabled => false is skipped.

public function beforeAction(yii\base\Action $action): bool

Disables the application log targets when $enableDebugLogs is false, applies the access check, and detaches the toolbar/header listeners so the debugger response is not polluted with self-debug data.

Parameters

ParameterTypeDescription
$actionyii\base\ActionAction about to run.

Returns

bool: true when the action may run; false to stop the dispatch.

Throws

public function bootstrap(yii\base\Application $app): void

Wires the debug log target, the toolbar/header listeners, the error-page injection hook, and the debugger URL rules onto the application.

Called by Yii during the application bootstrap phase (when this module is listed in bootstrap).

Parameters

ParameterTypeDescription
$appyii\base\ApplicationApplication being bootstrapped.

Throws

public function createCapturePolicy(list<string> $additionalSensitiveKeys = []): PHPForge\Debug\Capture\CapturePolicy

Creates the shared persistent-data policy, optionally extending its exact-key list for one collector.

Parameters

ParameterTypeDescription
$additionalSensitiveKeyslist<string>Collector-specific exact keys added without weakening global rules.

Returns

CapturePolicy: Shared policy covering the global rules and the collector-specific keys.

Throws

public function getCollectorCoordinator(): PHPForge\Debug\Collector\CollectorCoordinator

Returns the validated collector coordinator used by the request log target.

Returns

PHPForge\Debug\Collector\CollectorCoordinator: Configured collector coordinator.

Throws

public function getLogTarget(): yii\debug\LogTarget

Returns the initialized LogTarget, raising when the module has not been bootstrapped.

Returns

LogTarget: Initialized log target of this module.

Throws

public function getPanelRegistry(): PHPForge\Debug\Registration\PanelRegistry

Returns the effective panel catalog, which carries the display order and the IDs disabled by configuration.

Returns

PanelRegistry: Resolved panel catalog.

Throws

public function getShellContextFactory(): yii\debug\service\ShellContextFactory

Returns the factory building the page shell of every debugger action.

Registering ShellContextFactory under components replaces it, like any other module service.

Returns

yii\debug\service\ShellContextFactory: Resolved shell factory.

Throws

public function getToolbarHtml(): string

Returns the toolbar HTML: a <yii-debug-toolbar> custom element wired with data attributes the bundled JS reads.

Returns

string: Rendered <yii-debug-toolbar> element.

Throws

public static function getYiiLogo(): string

Returns the Yii logo as a data URI ready to drop into <img src="…"> or <link rel="icon">.

Uses the shared frontend file so every framework adapter renders the same Yii mark.

Returns

string: Logo as a data URI.

public function htmlTitle(): string

Resolves the page title used in the debugger HTML: the literal $pageTitle string when set, the result of the configured callable, or the default Yii Debugger label.

Returns

string: Page title for the debugger HTML.

public function init(): void

Resolves the $dataPath alias and instantiates every configured panel.

Throws

public function injectToolbarOnErrorPage(yii\web\ErrorHandlerRenderEvent $event): void

Injects the debug toolbar into the rendered HTML of an error page (yiisoft/yii2#7616).

Wired in bootstrap() as a listener for ErrorHandler::EVENT_AFTER_RENDER; the event fires after renderException() produces the HTML body but before the response is sent, so handlers may rewrite the output.

Parameters

ParameterTypeDescription
$eventyii\web\ErrorHandlerRenderEventRender event carrying the error-page HTML.

Throws

public function renderToolbar(yii\base\Event $event): void

Renders the mini-toolbar at the end of the page body.

Wired in bootstrap() as a listener for View::EVENT_END_BODY. The toolbar template is rendered dynamically while its runtime URL is resolved through the Yii2 asset manager.

Parameters

ParameterTypeDescription
$eventyii\base\EventEnd-of-body event raised by the view.

Throws

public static function route(string $action, array<string, yii\debug\TValue> $params = []): non-empty-array<int|string, string|yii\debug\TValue>

Builds a module-absolute route array for the given debugger action.

Resolves the module ID from the standalone action currently being dispatched, so widgets and views can build links without a controller context; outside a debugger dispatch the conventional debug module ID is used.

Parameters

ParameterTypeDescription
$actionstringDebugger action ID.
$paramsarray<string, yii\debug\TValue>Query parameters merged into the route array.

Returns

non-empty-array<int|string, string|yii\debug\TValue>: Route array ready for Url::to().

public function setDebugHeaders(yii\base\Event $event): void

Sets headers carrying debug data on AJAX responses so the toolbar can resolve the captured tag and link back to the full view.

Parameters

ParameterTypeDescription
$eventyii\base\EventResponse event raised after the action ran.

Throws

public static function setYiiLogo(string $logo): void

Sets the logo data URI returned by getYiiLogo().

Parameters

ParameterTypeDescription
$logostringLogo as a data URI.
protected function checkAccess(yii\base\Action|null $action = null): bool

Returns whether the current request is allowed to access the debugger.

Decided by AccessGuard from $allowedIPs, $allowedHosts, and the optional $checkAccessCallback, for the IP the current request carries.

Parameters

ParameterTypeDescription
$actionyii\base\Action|nullAction being dispatched, or null outside an action context.

Returns

bool: true when the request may reach the debugger; false otherwise.

Throws

protected function coreActionMap(): array<string, class-string>

Built-in standalone actions dispatched through Module::$actionMap, keyed by action ID.

Returns

array<string, class-string>: Action classes indexed by action id.

protected function coreCollectors(): array<string, array<string, mixed>|string>

Built-in collectors paired by stable ID with their presentation panels.

Array keys are a configuration-merge convenience and must match each collector’s CollectorInterface::id() so a user entry under the same key replaces the built-in collector.

Returns

array<string, array<string, mixed>|string>: Collector definitions indexed by collector id.

protected function corePanels(): array<string, array<string, mixed>|class-string<yii\debug\Panel>|class-string<PHPForge\Debug\Panel>|string>

Returns the built-in panel configurations, ordered as the request itself unfolds.

The primary navigation lists Request, Logs, Events, Profiling, Database, Mail, Queue, User, Dump, and Asset Bundles. config opens the list but is surfaced through the brand bar rather than the panel nav; router only feeds Request.

CoreDefinitions::merge() drops a built-in whose optional package is not installed (queue without yii\queue\Queue).

Returns

array<string, array<string, mixed>|class-string<Panel>|class-string<PHPForge\Debug\Panel>|string>: Panel definitions indexed by panel id.

protected function createStandaloneAction(string $route): yii\base\Action|null

Resolves a debugger endpoint from Module::$actionMap before falling back to convention-based discovery.

Application-level dispatch of a module-prefixed route (for example debug/db-explain) reaches this method through Module::createStandaloneAction(). Convention discovery derives a root-namespace class from the action ID (db-explain becomes DbExplainAction) and cannot see the sub-namespaced panel action classes (ExplainAction, JobAction), so the mapped entries are consulted first to keep those routes reachable.

Parameters

ParameterTypeDescription
$routestringAction route relative to this module.

Returns

yii\base\Action|null: Resolved action, or null when the route matches none.

Throws

protected function defaultVersion(): string

Returns the default module version string.

Returns

string: Version label reported for this module.

protected function initActionMap(): void

Hands the built-in, panel-declared, and configured standalone actions to StandaloneActionResolver and stores the merged map on Module::$actionMap.

Throws

protected function initCollectors(): void

Hands the built-in and configured collector definitions to CollectorRegistrar and stores the resolved collectors with the coordinator driving them.

Each resolved collector is instrumented right away: initPanels() runs afterwards and a panel constructor may already hit the framework, so instrumentation installed only at Application::EVENT_BEFORE_REQUEST would miss the debugger’s own bootstrap work.

Throws

protected function initPanels(): void

Hands the built-in and configured panel definitions to PanelRegistrar and stores the resolved panels with the catalog describing their display order.

Throws

protected function initPanelServices(): void

Registers every enabled panel in the module service locator under its own class and each ancestor class below Panel.

Standalone actions receive the registered instance through a typed run() parameter resolved by the standalone-action binder, so a configured panel subclass satisfies a built-in type hint such as DbPanel $panel. The generic Panel base class is never registered because multiple panels would compete for it; when panels share a class chain, the later entry in $panels order wins, matching the action ID precedence in initActionMap().

protected function resetGlobalSettings(): void

Resets application-wide settings the debugger should not inherit from the host application (currently the asset bundles registry).

protected function setDebuggerResponseHeaders(yii\web\Response $response): void

Applies the debugger response hardening policy.

Kept as an extension point so applications can customize the policy without replacing the complete beforeAction() lifecycle.

Parameters

ParameterTypeDescription
$responseyii\web\ResponseResponse about to be sent.