What (type of) classes are generated in Magento 2?

There are different reasons to generate different entities:

Proxy - it's used for lazy-loading. But each type requires separate proxy class so that would be annoying for developers to write them manually so Magento generates them. Yo will only find references to Proxies in di.xml

Factory - is a class that is used to create non-injectables (entities). Same as proxies. PHP doesn't have generics yet, so we auto-generate factories not to make developer write boilerplate code. You will interact with factories across Magento code. Most probably you will require your own factories for your entities. Just ask for corresponding factory in constructor and it will get generated on the next run or during compiler run.

Interceptor - is a infrastructure class, that is used by Interception component. As Flyingmana and Phil Winkle noticed you should not interact with them anyhow.

There are a bunch of other entities generated (like Logger for object graph profiling mode) but these 3 are most important.

Magento 2 can also be compiled. Compilation makes DI and Interception faster. All code generation and compilation can be done with dev/tools/Magento/Tools/Di/compiler.php


From the Concept:

You dont need to know which type of classes get auto generated, as you never have to touch or use them , not even you should.

They get (still?) generated on the fly, but should later get generated via cli command or similar.

The list which types exist could grow any time, when the internal parts get the need for a new one. But access to them would always happen hidden behind the normal documented APIs ( commonly known as function calls )


This is how Magento generates the aspect-oriented approach to the new platform; by actually generating the before, around, and after "events" instead of dynamically dispatching them. This strikes a balance of convenience to the programmer and performance for the platform.

Some techniques such as the auto dependency injection are flattened into the generated classes rather than executed via reflection - again - this is a technique to improve performance.

Tags:

Class

Magento2