Created
June 22, 2015 14:13
-
-
Save tomwalder/76d9fad64c2f73199791 to your computer and use it in GitHub Desktop.
Potential Di DB studd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Docnet; | |
class LazyDB | |
{ | |
protected $obj_db = NULL; | |
protected $obj_db_settings = NULL; | |
public function getDb() | |
{ | |
if(NULL === $this->obj_db) { | |
$this->obj_db = new \Docnet\DB($this->obj_db_settings); | |
} | |
return $this->obj_db; | |
} | |
public function setConnectionSettings($obj_db_settings) | |
{ | |
$this->obj_db_settings = $obj_db_settings; | |
} | |
} | |
trait HasDB | |
{ | |
protected $obj_db = NULL; | |
protected $obj_lazy_db = NULL; | |
protected function getDb() | |
{ | |
if(NULL === $this->obj_db) { | |
$this->obj_db = $this->obj_lazy_db->getDb(); | |
} | |
return $this->obj_db; | |
} | |
public function setDb($obj_lazy_db) | |
{ | |
$this->obj_lazy_db = $obj_lazy_db; | |
} | |
} | |
trait HasDBv1 | |
{ | |
protected $obj_db = NULL; | |
protected $obj_db_settings = NULL; | |
protected function getDb() | |
{ | |
if(NULL === $this->obj_db) { | |
$this->obj_db = new \Docnet\DB($this->obj_db_settings); | |
} | |
return $this->obj_db; | |
} | |
public function setConnectionSettings($obj_db_settings) | |
{ | |
$this->obj_db_settings = $obj_db_settings; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment