I implemented a MVC Framework with Generic DAO and I would like know if is correct. I did not have developed yet the MySQLDAO.
My controller class
class ClienteController {
public function __construct() { }
public function actionSubmit(){
$objCliente = new Cliente();
$objCliente->setNome($_POST['nome']);
$objCliente->setCodigo($_POST['codigo']);
$objCliente->getDAOFactory()->insert();
}
}
DAO Class for client, persistence.
class ClienteDAO implements IRecord {
const TABLE = 'cliente';
private $campos = array(
"codigo" => "cliCod",
"nome" => "cliNom"
);
private $DAOFactory;
public function __construct() {
$this->DAOFactory = new DAOFactory($this);
}
public function getDAOFactory() {
return $this->DAOFactory->getInstance();
}
}
Model class
class Cliente extends ClienteDAO {
private $codigo;
private $nome;
public function __construct(){ }
public function getCodigo() {
return $this->codigo;
}
public function setCodigo( $codigo ) {
if ( $codigo > 0 ) {
$this->codigo = $codigo;
}
}
public function getNome() {
return $this->nome;
}
public function setNome( $nome ) {
$this->nome = $nome;
}
}
Database class
class MySQLDao implements iDAO {
public function insert() {
}
public function update() {
}
public function delete() {
}
public function limit() {
}
public function orderBy() {
}
public function findAll() {
}
public function addColumns() {
}
public function addGroupBy() {
}
public function addOrderBy() {
}
public function addHaving() {
}
public function addCustomizedHaving() {
}
public function addColumSubQuery() {
}
public function addAnd() {
}
public function addOr() {
}
public function checkExistanceColumn() {
}
}
Factory class
class DAOFactory {
private $objeto;
private $factory;
public function __construct($obj, $banco = null) {
$this->factory = $banco;
$this->objeto = $obj;
}
public function getFactory() {
return $this->factory;
}
public function setFactory($factory) {
$this->factory = $factory;
}
public static function getInstance() {
if ($this->getFactory() == null) {
return new MySQLDAO($this->getObjeto());
}
}
public function getObjeto() {
return $this->objeto;
}
}
Interfaces
interface IDAO {
public function insert();
public function update();
public function delete();
public function limit();
public function orderBy();
public function findAll();
public function addColumns();
public function addGroupBy();
public function addOrderBy();
public function addHaving();
public function addCustomizedHaving();
public function addColumSubQuery();
public function addAnd();
public function addOr();
public function checkExistanceColumn();
}
interface IRecord {
public function getDAOFactory();
}