Ferreteria/v0.3/class/tHasTableSource

From Woozle Writes Code
< Ferreteria‎ | v0.3‎ | class
Revision as of 13:15, 7 January 2019 by htyp>Woozle (Woozle moved page Ferreteria/class/tTableSource to Ferreteria/class/tHasTableSource: more descriptive)
Jump to navigation Jump to search

Template:Page/code/class

trait tTableSource {
    use tQueryableSource;

    private $db;
    public function SetDatabase(cDatabaseConnection $db) {
	$this->db = $db;
    }
    protected function GetDatabase() : cDatabaseConnection {
	if (is_null($this->db)) {
	    $sClass = get_class($this);
	    throw new \exception("Tried to retrieve db object before it has been set in class '$sClass'.");
	}
	return $this->db;
    }

    abstract protected function GetTableName();
    
    // ALIAS
    protected function SourceString_forSelect() {
        $sName = $this->GetTableName();
        return "`$sName`";
    }

}