Find file History
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
Tests Merge branch 'master' into feature/class-instead-of-namespace Mar 9, 2017
uml PHP7 DataMapper Sep 22, 2016
README.rst Improve grammar: these code > this code Apr 4, 2017
StorageAdapter.php PHP7 DataMapper Sep 22, 2016
User.php PHP7 DataMapper Sep 22, 2016
UserMapper.php PHP7 DataMapper Sep 22, 2016

README.rst

Data Mapper

Purpose

A Data Mapper, is a Data Access Layer that performs bidirectional transfer of data between a persistent data store (often a relational database) and an in memory data representation (the domain layer). The goal of the pattern is to keep the in memory representation and the persistent data store independent of each other and the data mapper itself. The layer is composed of one or more mappers (or Data Access Objects), performing the data transfer. Mapper implementations vary in scope. Generic mappers will handle many different domain entity types, dedicated mappers will handle one or a few.

The key point of this pattern is, unlike Active Record pattern, the data model follows Single Responsibility Principle.

Examples

  • DB Object Relational Mapper (ORM) : Doctrine2 uses DAO named as "EntityRepository"

UML Diagram

Alt DataMapper UML Diagram

Code

You can also find this code on GitHub

User.php

.. literalinclude:: User.php
   :language: php
   :linenos:

UserMapper.php

.. literalinclude:: UserMapper.php
   :language: php
   :linenos:

StorageAdapter.php

.. literalinclude:: StorageAdapter.php
    :language: php
    :linenos:

Test

Tests/DataMapperTest.php

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