Expand description
Plugin API for the mir PHP static analyzer, modeled on Psalm’s plugin event handlers (https://psalm.dev/docs/running_psalm/plugins/plugins_overview/).
A plugin implements MirPlugin, declares which hooks it wants via
MirPlugin::hooks, and is registered into a PluginRegistry that the
host process installs globally with install. The analyzer snapshots the
registry once per analysis pass; when no registry is installed every hook
site reduces to a single Option check.
Plugins come in two flavors:
- Rust plugins — compiled in (registered directly) or loaded from a
cdylib at runtime (
dylibfeature, see [dylib]). - Psalm PHP plugins — reused through a PHP host subprocess
(
psalm-bridgefeature, see [psalm]).
Re-exports§
Macros§
- export_
plugin - Export a plugin constructor from a cdylib crate:
Structs§
- After
Codebase Populated Event - Counterpart of Psalm’s
AfterCodebasePopulatedEvent. Fired once per batch run after definition collection, before body analysis. - After
Expression Analysis Event - Counterpart of Psalm’s
AfterExpressionAnalysisEvent. - After
Function Call Analysis Event - Counterpart of Psalm’s
AfterFunctionCallAnalysisEvent.return_typestarts as the analyzer’s inferred type and may be replaced. - After
Method Call Analysis Event - Counterpart of Psalm’s
AfterMethodCallAnalysisEvent. - After
Statement Analysis Event - Counterpart of Psalm’s
AfterStatementAnalysisEvent. - Array
Property Default - An array-literal property default declared on a class, exposed to
ClassPropertyProviderEventso a plugin can interpret framework conventions like Eloquent’sprotected $casts = [...]without re-parsing. - Class
Property Provider Event - Counterpart of Psalm’s
PropertiesProviderInterface: supply the type of a property that is not declared on the class (nor reachable via@property), e.g. an Eloquent attribute synthesized from$casts. Dispatched when a property access misses on a class whose own FQCN or an ancestor is listed inMirPlugin::class_property_classes. - Function
Return Type Provider Event - Counterpart of Psalm’s
FunctionReturnTypeProviderEvent. - Hook
Flags - Which event hooks a plugin subscribes to. Sites only construct events and dispatch when at least one registered plugin set the matching flag, so an unset flag keeps that hook zero-cost.
- Issue
- Method
Return Type Provider Event - Counterpart of Psalm’s
MethodReturnTypeProviderEvent. - Plugin
Declaration - Entry-point record a Rust cdylib plugin exports under the symbol
MIR_PLUGIN_DECLARATION. Useexport_plugin!instead of writing this by hand. - Plugin
Issue - An issue raised by a plugin. Converted by the analyzer into
IssueKind::PluginIssuewith a proper sourceLocation. - Plugin
Registry - Type
Enums§
- Provided
Type - A type contributed by a plugin.
Parsecarries a docblock-syntax type string (e.g.list<non-empty-string>) that the analyzer resolves with its own type parser in the context of the analyzed file — this is what the Psalm bridge returns, since PHP-side plugins produce type strings. - Severity
Constants§
- MIR_
PLUGIN_ API_ VERSION - Bumped whenever the
MirPlugintrait or event types change incompatibly. Dylib plugins built against a different version are refused at load time.
Traits§
- MirPlugin
- A mir plugin. Hook methods take
&selfand may run concurrently from rayon workers — use interior mutability with proper synchronization.
Functions§
- install
- Install the process-wide plugin registry. The analyzer takes an
Arcsnapshot per pass, so re-installing affects subsequent passes only. - normalize_
id - Normalize a function id or FQCN for provider-map lookup: lowercase, no leading backslash.
- snapshot
- Snapshot the installed registry.
Nonewhen no plugins are loaded — the common case, which every hook site checks first.