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();
\Magento\Framework\App\EnvironmentFactory::createEnvironment
public function createEnvironment()
{
switch ($this->getMode()) {
case Compiled::MODE:
return new Compiled($this);
break;
default:
return new Developer($this);
}
}
\Magento\Framework\App\EnvironmentFactory::getMode
const AREA_GLOBAL = 'global';
private function getMode()
{
if (file_exists(ConfigLoader\Compiled::getFilePath(Area::AREA_GLOBAL))) {
return Compiled::MODE;
}
return Developer::MODE;
}
\Magento\Framework\App\ObjectManager\ConfigLoader\Compiled::getFilePath
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.
Explore related questions
See similar questions with these tags.