mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-06-09 23:45:05 +02:00
injecting a database abstract layer (instead of creting it in constructor)
This commit is contained in:
parent
e8adb1874c
commit
d9e5b562c4
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns;
|
namespace DesignPatterns\DataMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DataMapper pattern
|
* DataMapper pattern
|
||||||
@ -16,24 +16,21 @@ namespace DesignPatterns;
|
|||||||
* entity types, dedicated mappers will handle one or a few.
|
* entity types, dedicated mappers will handle one or a few.
|
||||||
* (FROM http://en.wikipedia.org/wiki/Data_mapper_pattern)
|
* (FROM http://en.wikipedia.org/wiki/Data_mapper_pattern)
|
||||||
*
|
*
|
||||||
|
* The key point of this pattern is, unlike Active Record pattern, the datamodel
|
||||||
|
* follows Single Responsibility Principle.
|
||||||
*
|
*
|
||||||
* Examples:
|
* Examples:
|
||||||
* - DB Object Relational Mapper (ORM)
|
* - DB Object Relational Mapper (ORM) : Doctrine2 uses DAO named as "EntityRepository"
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class UserMapper
|
class UserMapper
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $_adapter;
|
protected $_adapter;
|
||||||
|
|
||||||
public function __construct(array $options = null)
|
public function __construct(DBAL $dbLayer)
|
||||||
{
|
{
|
||||||
/**
|
$this->_adapter = $dbLayer;
|
||||||
* create new Database connector on $_adapter using specific table
|
|
||||||
*
|
|
||||||
* $_adapter var could be a specific to a table class or a generic
|
|
||||||
* interface for connecting to Database and do certain jobs
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user