Skip to content

[Issue] compiled interceptors module #30311

Open
@m2-assistant

Description

@m2-assistant

This issue is automatically created based on existing pull request: #22826: compiled interceptors module


Description (*)

At Creatuity we have developed a module that generates Interceptors code using app config instead of a boilerplate that reads config at runtime.

https://github.com/creatuity/magento2-interceptors

We believe it changes performance and debugging magento significantly and it is worth to consider making it a part of the core witch this pull request does.

Any comments welcome.

Manual testing scenarios (*)

to use in developer mode in app/etc/di.xml replace:

<item name="interceptor" xsi:type="string">\Magento\Framework\Interception\Code\Generator\Interceptor</item>

with:

<item name="interceptor" xsi:type="string">\Magento\Framework\CompiledInterception\Generator\CompiledInterceptor</item>

clear generated files and cache:

rm -rf generated/* && rm -rf var/cache/* && bin/magento cache:clean

generated interceptors instead of boilerplate that reads 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);
    }
}

should have a code built using config like:

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);
    }
}

Contribution checklist (*)

  • [*] Pull request has a meaningful description of its purpose
  • [*] All commits are accompanied by meaningful commit messages
  • [*] All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Pull Request in Progress

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions