yaml或注释中的注释2 [英] yaml or annotation mapping in doctrine 2

查看:173
本文介绍了yaml或注释中的注释2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪一个在教条2中选择yaml或注释映射?我决定在symfony框架中以教义2作为orm。使用基于注释的映射为实体,我将不得不编写大量的代码,设置器和getter,映射信息。使用xml或yaml我不必写很多列的定义和元数据。但是在教义文档中,他们使用注释和很多示例,使用注释,而使用yaml或xml很少。所以我有两难选择是否选择山药或注释?
另外对于注释,我可以在 http://docs.doctrine-project.org/en/latest/reference/annotations-reference.html 。但是我没有看到yaml或xml中的等效的注释代码。如何将注释转换为等效的yaml表达式?

Which one to choose yaml or annotation mapping in doctrine 2? I decided to go with doctrine 2 as orm in symfony framework. Using annotation based mapping for entity, I would have to write lot of code, setters and getters, mapping information. Using xml or yaml I wont have to write much just the column defintion and meta data. But in doctrine documentation, they have used annotation and lots of example using annotation and few with yaml or xml. So I am in dilemma whether to choose yaml or annotation? Also for annotation, i see the documentation for every annotation at http://docs.doctrine-project.org/en/latest/reference/annotations-reference.html. But I dont see the equivalent code of annotation in yaml or xml. How do I convert the annotation to equivalent yaml expression ?

推荐答案

这基本上是偏爱。

这是我对事物的看法:

注释优点:


  • 更容易使用,因为它们接近于他们描述的内容(属性)

  • 很多例子使用它们,就像你已经注意到的那样

yaml / xml的优点

Pros of yaml/xml


  • 这将保留域对象干净,所以永远不会从持久层泄漏到域中(即使以评论的形式)

如果您更改数据库或域名,您仍然需要以任何一种形式进行维护,所以从这个角度来看,从任何方向都没有任何实际的优势。

If you change the db or the domain, you still have to maintain them in either form, so there's no real advantage in any direction from that standpoint.

从性能角度看,在生产中应该使用教义的缓存来缓存映射,所以他们在这里也是平等的。

From a performance standpoint, in production you should be using doctrine's caching to cache the mappings, so they are equal here too.

Regardi这样做:我必须编写很多代码,设置器和getter,映射信息:

Regarding this: "I would have to write lot of code, setters and getters, mapping information":

Doctrine需要私有/受保护的属性,所以你仍然会写吸气器和设置器。而您仍然会在另一个地方写出映射信息。

Doctrine requires private/protected properties, so you'll still be writing getters and setters. And you'll still be writing the mapping info, just in another place.

个人而言,我会使用注释,因为查找示例和信息更容易如果你需要它们。

Personally, I'd go with annotations, since it's a lot easier to find examples and info if you need them.

这篇关于yaml或注释中的注释2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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