I tried to search deeper in Magento 2 code generation process and found some points, which confused me. I use Magento v2.0.1-ce in production mode. Firstly, I found strange dependency in Magento/Framework/App/ObjectManagerFactory.php:120

$definitions = $definitionFactory->createClassDefinition($deploymentConfig->get('definitions')); 

I looked in console command setup:config:set help list and found only '--definition-format' parameter. I set it and got

'definition' => array ('format' => 'serialized',),

node in env.php. But it isn't requested param, so $deploymentConfig still return null. The case in, that without this param, Magento 2 add Code Generation Autoload in autoload's chain.

public function createClassDefinition($definitions = false)
    if ($definitions) {
        if (is_string($definitions)) {
            $definitions = $this->_unpack($definitions);
        $definitionModel = self::$definitionClasses[$this->_definitionFormat];
        $result = new $definitionModel($definitions);
    } else {
        $autoloader = new \Magento\Framework\Code\Generator\Autoloader($this->getCodeGenerator());
        spl_autoload_register([$autoloader, 'load']);

        $result = new Runtime();
    return $result;

So, question is: what is 'definitions' param in configs and in what way I should set it? Or it is OK, that Magento 2 still use Code Generator Autoload in production mode? Finally, on what depend this param? Secondly, after switch on production mode, Magento 2 called 'setup:di:compile-multi-tenant' and I found, that file 'global.ser' doesn't generate with this command. As I understand, Magento 2 use this file for determination actual environment mode: Magento/Framework/App/ObjectManagerFactory.php:126

$env =  $enFactory->createEnvironment();


public function createEnvironment()
    switch ($this->getMode()) {
        case Compiled::MODE:
            return new Compiled($this);
            return new Developer($this);


const AREA_GLOBAL = 'global';

private function getMode()
    if (file_exists(ConfigLoader\Compiled::getFilePath(Area::AREA_GLOBAL))) {
        return Compiled::MODE;

    return Developer::MODE;


public static function getFilePath($area)
    return BP . '/var/di/' . $area . '.ser';

On environment depend ObjectManager factory and configs. So, after code generation via 'setup:di:compile-multi-tenant' Magento Object Manager will still work in developer mode?

1 Answer 1


Code generator should not be added to autoload in production mode because all auto-generated entities are expected to be available in definition files (those with .ser extension). There is no need to modify definitions in config, just run magento setup:di:compile-multi-tenant. In your case the problem is that definitions are not generated, try to investigate why.

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.