function insert(\woo\domain\DomainObject $obj){ //将对象数据插入数据库
$this->doInsert($obj);
}
//需要在子类中实现的各抽象方法
abstract function update(\woo\domain\DomainObject $objet);
protected abstract function doCreateObject(array $array);
protected abstract function selectStmt();
protected abstract function doInsert(\woo\domain\DomainObject $object);
}
//这里只建立一个VenueMapper类用于理解
class VenueMapper extends Mapper {
function __construct (){
parent::__construct(); //各种sql语句对象
$this->selectStmt = self:PDO->prepare("select * from venue where id=?");
$this->updateStmt = self:PDO->prepare("update venue set name=?,id=? where id=?");
$this->insertStmt = self:PDO->prepare("insert into venue (name) values(?)");
}
protected function getCollection(array $raw){ //将Space数组转换成对象
return new SpaceCollection($raw,$this); //这个类的基类在下面
}
protected function doCreateObject (array $array){ //创建对象
$obj = new \woo\domain\Venue($array['id']);
$obj->setname($array['name']);
return $obj;
}