Ferreteria/v0.3/class/tHasTableSource: Difference between revisions

From Woozle Writes Code
< Ferreteria‎ | v0.3‎ | class
Jump to navigation Jump to search
(Created page with "{{page/code/class|ferreteria}} <source lang=php> trait tTableSource { use tQueryableSource; private $db; public function SetDatabase(cDatabaseConnection $db) { $...")
 
m (Woozle moved page Ferreteria/class/tTableSource to Ferreteria/class/tHasTableSource: more descriptive)
(No difference)

Revision as of 13:15, 7 January 2019

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`";
    }

}