2022 · Magento development · In progress
Magento 2 Analyzer
An n98-magerun2 plugin that lists the plugins, observers and rewrites of a Magento 2 store, with a web interface to browse them.
- Role
- Design and development
- Period
- Aug 2022 — present
- Stack
- Angular · Magento 2 · PHP · TypeScript
- Team
- Solo
The problem
In a Magento 2 flow, a method can be intercepted by plugins from several modules, an event can have observers all over the store and a class may have been replaced by another. Finding out means digging through dozens of di.xml and events.xml files.
On the command line
There are three n98-magerun2 commands, with filters by module, method, class, type and status, and an option to include disabled modules.
frobou:show:pluginlists each plugin with its type (before, after or around), the method and class it intercepts, and the file and line.frobou:show:observerlists the observers of each event and searches the code for where the event is dispatched.frobou:show:rewritelists the preferences, the rewritten classes.
n98-magerun2 frobou:show:plugin "{{Magento:save:Model:after-before:1}}"
n98-magerun2 frobou:show:observer -g
Plugins
The same search has a web interface, copied into the store, with one page per kind of artifact. The plugins page, in the image at the top, explains what a plugin is with the di.xml snippet that declares it, offers the filters and lists the modules with how many plugins each one has. Expanded, each module shows its plugins, and one click opens the file at the right line in VS Code or PhpStorm. The interface is in Portuguese.
Observers
The observers page lists who listens to each event and also counts the places in the code that dispatch events, found by searching the code itself, which events.xml does not show.

Rewrites
The rewrites page lists the preferences: which concrete class takes the place of each interface, and which classes replace others.

How it is built
PHP on top of the n98-magerun2 command API, using Reflection to reach the file and line of each method. The interface is Angular, with Angular Material, and has a light and a dark theme.
1852
plugins found in an Adobe Commerce installation, across 337 modules
1007
observers, and 450 places in the code that dispatch events
1910
rewrites, across 266 modules