Code generation

One of the neat features of the Magento application is code generation. Code generation, as implied by its name, generates nonexistent classes. These classes are generated in Magento's var/generation directory.

The directory structure within var/generation is somewhat similar to that of the core vendor/magento/module-* and app/code directories. To be more precise, it follows the module structure. The code is generated for something that is called Factory, Proxy, and Interceptor classes.

The Factory class creates an instance of a type. For example, a var/generation/Magento/Catalog/Model/ProductFactory.php file with a Magento\Catalog\Model\ProductFactory class has been created because somewhere within the vendor/magento directory and ...

Get Magento 2 Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.