7

I recently created a basic routing configuration for a test module

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd">
    <router id="standard">
        <route id="helloworld" frontName="helloworld">
            <module name="Pulsestorm_Helloworld" />
        </route>
    </router>    
</config>

and then created a controller file at

app/code/Pulsestorm/Helloworld/Controller/Index/Index.php

Everything work as expected -- but I was surprised to discover that Magento had automatically created an interceptor for my new controller.

var/generation/Pulsestorm/Helloworld/Controller/Index/Index/Interceptor.php

I didn't configure any plugins for my controller -- so I'm little confused as to why Magento generated an interceptor.

What makes Magento 2 automatically create an Interceptor for new controllers?

1 Answer 1

5

Plugins are defined on interface. So if you define plugin for concrete interface

<type name="Magento\Framework\App\ActionInterface">
    <plugin name="log" type="Magento\Logging\App\Action\Plugin\Log" sortOrder="95"/>
</type>

then plugin will be work on all classes that implements it and IT will generate interceptor proxies for them. That's why Magento 2 will automatically create a interceptor for your controller (that implements Magento\Framework\App\ActionInterface).

2
  • thank you! Quick question -- where are you seeing the <type/> definition for Magento\Framework\App\ActionInterface -- no such thing shows up in my installation (or, at least, I couldn't find it with grep/ack) Commented Sep 4, 2015 at 18:20
  • Sorry for late answer. In Magento/Backend/etc/adminhtml/di.xml we have <type name="Magento\Framework\App\Action\Action"> <plugin name="storeCheck" disabled="true" /> </type>
    – KAndy
    Commented Sep 30, 2015 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.