Using the entity repositories

Entity repositories are classes responsible for accessing and managing entities. Just like entities are related to the database rows, entity repositories are related to the database tables.

We have already used default entity repositories provided by Doctrine to retrieve the entities in the previous chapters. All the DQL queries should be written in the entity repository related to the entity type they retrieve. It hides the ORM from other components of the application and makes it easier to re-use, refactor, and optimize the queries.

Note

Doctrine entity repositories are an implementation of the Table Data Gateway design pattern. For more details, visit the following website:

http://martinfowler.com/eaaCatalog/tableDataGateway.html ...

Get Persistence in PHP with Doctrine ORM now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.