对象间的组织关系和关系数据库中的表是不通的。设计一个独立的类来负责在领域模型中隐藏数据库操作并管理数据转换中不可避免的冲突
<?php
namespace woo\mapper;
using \woo\base\ApplicationRegistry;
abstract class Mapper{
protected static PDO)){
dsn)){
// throw new \woo\base\AppException("no dsn");
}
}
self::dsn);
self::id){
id));
this->selectStmt()->fetch();
array)){return null;}
if( ! isset(object =
array);
return array){
this->doCreateObject(
obj;
}
function insert(\woo\domain\DomainObject this->doInsert(
obj);
protected abstract function doCreateObject(array object);
protected abstract function selectStmt();
}
class VenueMapper extends Mapper{
function __construct()
{
parent::__construct();
PDO->prepare("select * from venue where id=?");
PDO->prepare("update venue set name=?, id=?, where id=?");
PDO->prepare("insert into venue values(?)");
}
function getCollection(array raw,
array){
array[
obj->setname(
obj;
}
protected function
}
网友评论