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 its code, there is a call to the Magento\Catalog\Model\ProductFactory
class, which originally does not exist in Magento. During runtime, when {someClassName}Factory
is called in the code, Magento creates a Factory class under the var/generation...