Skip to content

Instantly share code, notes, and snippets.

@tomwalder
Created June 22, 2015 14:13
Show Gist options
  • Save tomwalder/76d9fad64c2f73199791 to your computer and use it in GitHub Desktop.
Save tomwalder/76d9fad64c2f73199791 to your computer and use it in GitHub Desktop.
Potential Di DB studd
<?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