从存储库获取时,Doctrine如何在不调用__construct方法的情况下创建实体? [英] How Doctrine create an entity without call __construct method when fetch from repository?
问题描述
我在构造函数中编写了下一个代码:
公共函数__construct()
{
die( 创建实体);
}
当我使用 new创建实体的实例时
运算子,例如:
$ entity = new Entity();
我看到创建实体
文本。 / p>
但是当我从回购中获取实体时:
$ em-> ; getRepository('AcmeDemoBundle:Entity')-> find(1)
Doctrine创建一个对象实体而未调用 __ construct()
方法,并且看不到正在创建实体
文本。
有人可以解释从存储库中加载时,Doctrine如何创建对象吗?
要创建没有调用构造器的实例,该构造器可用于 ReflectionClass :: newInstanceWithoutConstructor
Doctrine在文档\ORM\映射\ClassMetadataInfo :: newInstance()
I wrote next code in constructor:
public function __construct()
{
die('creating entity');
}
When I create instance of entity with new
operator like:
$entity = new Entity();
I see the creating entity
text.
But when I get entity from repo:
$em->getRepository('AcmeDemoBundle:Entity')->find(1)
Doctrine create an object of entity without calling __construct()
method and I don't see the creating entity
text.
Can anybody explain how Doctrine creating an object when loading them from repository?
To create an instance without invoking constructor available with ReflectionClass::newInstanceWithoutConstructor
Doctrine create instances of mapped entities without invoking constructor in Doctrine\ORM\Mapping\ClassMetadataInfo::newInstance()
这篇关于从存储库获取时,Doctrine如何在不调用__construct方法的情况下创建实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!