1: <?php
2:
3: namespace Alchemy\core\query;
4: use Alchemy\core\Element;
5: use Alchemy\util\promise\IPromisable;
6:
7:
8: /**
9: * Represents a reference to a column in SQL query
10: */
11: class ColumnRef extends Element implements IQueryValue, IPromisable {
12:
13: protected $schema;
14: protected $table;
15:
16:
17: public static function list_promisable_methods() {
18: return array(
19: 'copy' => "Alchemy\core\query\ColumnRef",
20: 'schema' => "Alchemy\core\schema\Column",
21: 'table' => "Alchemy\core\query\TableRef");
22: }
23:
24:
25: /**
26: * Build and return a Predicate by comparing this
27: * column to another IQueryValue
28: *
29: * @param $name Operator Name: and, or
30: * @param $args array([0] => IQueryValue, ...) IQueryValue to compare to
31: */
32: public function __call($name, $args) {
33: foreach ($args as &$value) {
34: if (!($value instanceof IQueryValue)) {
35: $value = new Scalar($value);
36: }
37: }
38:
39: array_unshift($args, $this);
40: return Predicate::$name($args);
41: }
42:
43:
44: public function __construct($schema, TableRef $table) {
45: $this->schema = $schema;
46: $this->table = $table;
47:
48: $this->addTag('expr.value');
49: $this->addTag('sql.compile', "ColumnRef");
50: }
51:
52:
53: public function getDescription($maxdepth = 3, $curdepth = 0) {
54: $str = parent::getDescription($maxdepth, $curdepth);
55: return "$str ({$this->table->name()}#{$this->table->getID()}.{$this->name()})";
56: }
57:
58:
59: public function name() {
60: return $this->schema->getName();
61: }
62:
63:
64: public function schema() {
65: return $this->schema;
66: }
67:
68:
69: public function table() {
70: return $this->table;
71: }
72: }