In Magento 2 (beta9 and above) you can run this command php bin/magento setup:di:compile and all the interceptors, factories and proxies (and maybe others) will be generated in the var/generation folder for all the classes you have in your magento instance.
This is useful for live environments because otherwise the classes mentioned above will be generated at runtime when they are needed and could impact performance.
Is there a way to exclude some classes from this script so the interceptors will not be created when running the command?
As an example: I want for the controller Magento\Backend\Controller\Adminhtml\Dashboard\RefreshStatistics not to have interceptors generated.

  • Why do you need this?
    – Anton Kril
    May 27, 2015 at 6:49
  • @AntonKril. Stop asking questions and give me a solution :D. Now seriously, I'm trying to remove some modules and when doing so, the setup:di:compile fails because some parent classes are missing. The classes that extend those missing classes still exist but they are not used by the application. And I cannot remove them since they are in modules I need. See a full explanation below: magento.stackexchange.com/questions/69040/…
    – Marius
    May 27, 2015 at 7:01

2 Answers 2


for running from cli at least in earlier versions there is the exclude-pattern parameter. It was added to avoid problems when a class cant be processed correctly, like it happens for example with magento1 classes. The commands and arguments may have changed by converting them to console commands.

But I am not sure what your goal is, so I cant say if this is a good solution to use.

  • Here is what I trying to do. I'm removing some modules to see how far I can go. Among these modules is the Report module. But because of the tight coupling between Reports and Backend module there are still classes in the backend module that depend on the report module classes. I found a way to not use them, but since the di command parses the files it goes through the "ignored" classes and tries to build the interceptors. But this fails because the parent class of Magento\Backend\Controller\Adminhtml\Dashboard\RefreshStatistics for example, does not exist. So I need a way to exclude this.
    – Marius
    May 27, 2015 at 6:11
  • it seams that in the console command approach there is no exclude-pattern param. Or at least I didn't find it. I looked in DiCompileCommand::configure.
    – Marius
    May 27, 2015 at 6:21
  • I see, you could add an Issue asking for this functionality refering to this PR: github.com/magento/magento2/pull/986 or you use the changeset there to test how to add it temporary for your local build.
    – Flyingmana
    May 27, 2015 at 8:24

I hit the exact same issue (needing to exlcude a class from generation) as the library I was using used some funky autoloading where the "source class" didn't exist.

Giving me the error

Source class "\Phalcon\Http\Message\Request" for "Phalcon\Http\Message\RequestFactory" generation does not exist.

Having had a dig I found: Magento\Framework\Code\Generator::shouldSkipGeneration

This code checks if the class is defined as a virtual type, if so it isn't generated. So in this case I added

<virtualType name="Phalcon\Http\Message\RequestFactory" type="anything"></virtualType>

to my di.xml which seemed to get around it. Obviously doing


is never going to work, but that's okay because the code that uses that class doesn't use the object manager

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.