Skip to content

Instantly share code, notes, and snippets.

@sycobuny
Created May 27, 2012 16:50
Show Gist options
  • Save sycobuny/2815045 to your computer and use it in GitHub Desktop.
Save sycobuny/2815045 to your computer and use it in GitHub Desktop.
A good _QueryTable class?
<?php
class _QueryTable extends _QueryTableExpression {
private $identifier;
function __construct($identifier, $alias = null) {
$this->identifier = _QueryIdentifier::create($identifier, $alias);
}
public static function create($identifier, $alias = null) {
// this is probably a self-join that's aliased.
if ($alias) {
return new _QueryTable($identifier, $alias);
}
// from here on out, don't bother checking for aliases.
// any table expression is a stand-in for a table
if (is_a($identifier, '_QueryTableExpression')) {
return $identifier;
}
// pass off handling to the constructor
else {
return new _QueryTable($identifier);
}
}
public function sql_string() {
return $this->do_alias($this->identifier->sql_string());
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment