从存储库获取时,Doctrine 如何在不调用 __construct 方法的情况下创建实体? [英] How Doctrine create an entity without call __construct method when fetch from repository?

查看:32
本文介绍了从存储库获取时,Doctrine 如何在不调用 __construct 方法的情况下创建实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在构造函数中写了下一段代码:

I wrote next code in constructor:

public function __construct()
{
    die('creating entity');
}

当我使用 new 运算符创建实体实例时,例如:

When I create instance of entity with new operator like:

$entity = new Entity();

我看到 creating entity 文本.

但是当我从 repo 中获取实体时:

But when I get entity from repo:

$em->getRepository('AcmeDemoBundle:Entity')->find(1)

Doctrine 创建实体对象而不调用 __construct() 方法,我没有看到 creating entity 文本.

Doctrine create an object of entity without calling __construct() method and I don't see the creating entity text.

谁能解释 Doctrine 在从存储库加载对象时如何创建对象?

Can anybody explain how Doctrine creating an object when loading them from repository?

推荐答案

在不调用构造函数的情况下创建实例 ReflectionClass::newInstanceWithoutConstructor

To create an instance without invoking constructor available with ReflectionClass::newInstanceWithoutConstructor

Doctrine 创建映射实体的实例而不在 DoctrineORMMappingClassMetadataInfo::newInstance()

Doctrine create instances of mapped entities without invoking constructor in DoctrineORMMappingClassMetadataInfo::newInstance()

这篇关于从存储库获取时,Doctrine 如何在不调用 __construct 方法的情况下创建实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆