The Home for
Magento Excellence

Explore. Discover. Elevate. #magento

162
Modules Tested
98
Ready for Magento 2.4
64
Need Your Help
Stable v1.3.7
Ready to Install
Build tests pass on Magento 2.4.8-p3

Magento 2 Interceptor classes generator

creatuity/magento2-interceptors

New interceptors approach for Magento 2

94,379
Downloads
Below average
136
GitHub Stars
Above average
8mo ago
Last Release
5
Open Issues

Quality Score

3/5
Installs via Composer
DI compiles correctly
Templates compile
PHPStan

Recent Test History

Each release is tested against the latest Magento version at that time.

v1.3.7 on Magento 2.4.8-p3
Dec 15, 2025
v1.3.7 on Magento 2.4.8-p2
Aug 14, 2025
v1.3.7 on Magento 2.4.8
May 13, 2025
v1.3.7 on Magento 2.4.7-p4
Apr 23, 2025
v1.3.5 on Magento 2.4.7-p4
Feb 15, 2025
v1.3.5 on Magento 2.4.7-p3
Nov 14, 2024

+11 older tests

GitHub Repository
Source code & docs
Packagist
Version history
Issues & Support
Get help or report bugs

Share This Module's Status

Magento 2 Interceptor classes generator Magento compatibility status badge

README

Loaded from GitHub

ABOUT

This component changes the way Magento 2 generates Interceptor classes (a mechanism that allows plugins to work together).

Instead of generating boilerplate code it compiles the Interceptor using information from source code. This makes plugins slightly faster and as Magento uses a lot of plugins, even at its core, it lowers request time by ~10%. This is important in places where there is a lot of non-cached PHP logic going on (for example admin panel is noticeably faster).

The default method uses code that is called on nearly each method to see if there are any plugins connected, in generated code this is not required and call-stack is reduced.

Having plugins called directly also makes code easier to debug and bugs easier to find.

The Interceptors generated by this plugin are 100% compatible with the ones generated by Magento by default, so there is no need to change anything in your plugins.

VERSIONS

As Magento 2.4 introduced changes in Interceptors generator which are not backward compatible this module has separate branch for both Magento versions:

  • use 1.3.* for Magento 2.4 (branch: master)
  • use 1.2.* for Magento 2.3 (branch: magento23)

CONFIGURATION

This module adds following preference to work in developer mode:

<preference for="Magento\Framework\Interception\Code\Generator\Interceptor" type="Creatuity\Interception\Generator\CompiledInterceptor" />

And following preferences to work in production or default modes:

<preference for="Magento\Setup\Module\Di\Code\Generator\Interceptor" type="Creatuity\Interception\Generator\CompiledInterceptor" />
<preference for="Magento\Setup\Module\Di\Compiler\Config\Chain\InterceptorSubstitution" type="Creatuity\Interception\Generator\CompiledInterceptorSubstitution" />

Those are enabled by default in module di.xml.

However this module does not touch the default generation method so you can override above preferences to fallback to the default mechanism for all or selected modes.

TECHNICAL DETAILS

Instead of interceptors that read plugins config at runtime like this:

public function methodX($arg) {
    $pluginInfo = $this->pluginList->getNext($this->subjectType, 'methodX');
    if (!$pluginInfo) {
        return parent::methodX($arg);
    } else {
        return $this->___callPlugins('methodX', func_get_args(), $pluginInfo);
    }
}

This generator generates static interceptors like this:

public function methodX($arg) {
    switch(getCurrentScope()){
        case 'frontend':
            $this->_get_example_plugin()->beforeMethodX($this, $arg);
            $this->_get_another_plugin()->beforeMethodX($this, $arg);
            $result = $this->_get_around_plugin()->aroundMethodX($this, function($arg){
                return parent::methodX($arg);
            });
            return $this->_get_after_plugin()->afterMethodX($this, $result);
        case 'adminhtml':
            // ...
        default:
            return parent::methodX($arg);
    }
}

PROS

  • Easier debugging.

    • If you ever stumbled upon ___callPlugins when debugging you should know how painful it is to debug issues inside plugins.
    • Generated code is decorated with PHPDoc for easier debugging in IDE
  • Fastest response time (5%-15% faster in developer and production mode)

    • No redundant calls to ___callPlugins in call stack.
    • Methods with no plugins are not overridden in parent at all.
  • Implemented as a module and can be easily reverted to the default Generator\Interceptor

CONS

  • Each time after making change in etc plugins config, generated/code/* and var/cache/* needs to be purged
  • As this does not load plugins at runtime, might not work in an edge case of plugging into core Magento classes like PluginsList etc.

This content is fetched directly from the module's GitHub repository. We are not the authors of this content and take no responsibility for its accuracy, completeness, or any consequences arising from its use.

Back to All Modules