6. 亠仍舒亠仄 亳仆亠从亳
class Stores{
public function __construct($database) {
}
function add($data){
$query = 'INSERT INTO stores SET title=?
, assigned_user_id=?, type=?';
$this->_database
->query($query, $data);
}
VETMANAGER TEAM 26.4.12 弌. 6
10. 舒从 仗仍仂仂 DI
$stores = new Stores(new VMDatabase());
$stores = new Stores(
new VMDatabase()
, new VMRequest()
, new VMSession()
, new UserModel()
);
VETMANAGER TEAM 26.4.12 弌. 10
11. 舒从 仂仂仂 Phemto
public function __construct(VMDatabase $database) {
$this->_database = $database;
}
require_once 'phemto/phemto.php';
$injector = new Phemto();
$stores = $injector->create('Stores');
VETMANAGER TEAM 26.4.12 弌. 11
12. 舒从 仂仂仂 Phemto2
public function __construct($database) {
$this->_database = $database;
}
require_once 'phemto/phemto.php';
$injector = new Phemto();
$injector->forVariable('database')
->willUse(new Reused('VMDatabase'));
$stores = $injector->create('Stores');
VETMANAGER TEAM 26.4.12 弌. 12
14. ActiveRecord
class Stores {
function dataWrap($data){...}
protected function getEntity(){...}
function add($data){
$entity = $this->getEntity();
$entity->import($this->dataWrap($data));
$entity->save();
}
VETMANAGER TEAM 26.4.12 弌. 14