Skip to content

Latest commit

 

History

History
61 lines (43 loc) · 1.21 KB

README.rst

File metadata and controls

61 lines (43 loc) · 1.21 KB

Repository

Purpose

Mediates between the domain and data mapping layers using a collection-like interface for accessing domain objects. Repository encapsulates the set of objects persisted in a data store and the operations performed over them, providing a more object-oriented view of the persistence layer. Repository also supports the objective of achieving a clean separation and one-way dependency between the domain and data mapping layers.

Examples

  • Doctrine 2 ORM: there is Repository that mediates between Entity and DBAL and contains methods to retrieve objects
  • Laravel Framework

UML Diagram

Alt Repository UML Diagram

Code

You can also find this code on GitHub

Post.php

.. literalinclude:: Post.php
   :language: php
   :linenos:

PostRepository.php

.. literalinclude:: PostRepository.php
   :language: php
   :linenos:

MemoryStorage.php

.. literalinclude:: MemoryStorage.php
   :language: php
   :linenos:

Test

Tests/RepositoryTest.php

.. literalinclude:: Tests/RepositoryTest.php
    :language: php
    :linenos: