I am the second tip from pix0r. An additional abstraction is worth it only if it is a large project with a potentially long life and, possibly, with many developers. This is pretty much the basic rule that I follow, also in php with doctrine2 or in java with jpa (since doctrine2 strongly resembles jpa).
If you need additional abstraction, doctrine2 already has the ability to use repositories (repositories are very similar or even equal to DAOs, perhaps with a closer look at business terms and logic). There is a base class Doctrine \ ORM \ EntityRepository. Whenever you call EntityManager # getRepository ($ entityName), Doctrine will see if you have configured a custom repository class for this object. If not, it creates an instance of Doctrine \ ORM \ EntityRepository. You can configure your own repository class for the object in metadata, for example, in docblock annotations: @Entity (..., repositoryclass = "My \ Project \ Domain \ UserRepository"). Such a custom class must inherit from the EntityRepository and invoke the parent constructor accordingly. The base class already contains some basic search functions *.
Roman
source share