1: <?php
2:
3: namespace Alchemy\orm;
4: use Alchemy\core\query\Predicate;
5: use Alchemy\core\query\Query;
6: use Alchemy\core\query\TableRef;
7: use Alchemy\util\promise\Promise;
8:
9:
10: 11: 12:
13: class ORMTableRef extends TableRef {
14:
15: protected $predicate;
16: protected $relcache = array();
17:
18:
19:
20:
21:
22: public function __construct($schema, $predicate = null) {
23: parent::__construct($schema);
24: $this->predicate = $predicate;
25: }
26:
27:
28: public function __get($name) {
29: if (array_key_exists($name, $this->relcache)) {
30: return $this->relcache[$name];
31: }
32:
33: if ($this->schema->hasRelationship($name)) {
34: $rel = $this->schema->getRelationship($name)->getRef($this);
35: $this->relcache[$name] = $rel;
36: return $rel;
37: }
38:
39: return parent::__get($name);
40: }
41:
42:
43: public function all(Predicate $expr) {}
44:
45:
46: public function getDescription($maxdepth = 3, $curdepth = 0) {
47: $str = parent::getDescription($maxdepth, $curdepth);
48: $prd = $this->predicate ? "{$this->predicate->getDescription($maxdepth, $curdepth)}" : "";
49: return "$str {$prd}";
50: }
51:
52:
53: public function none(Predicate $expr) {}
54:
55:
56: public function predicate() {
57: if ($this->predicate instanceof Promise) {
58: $this->predicate = $this->predicate->expect();
59: }
60:
61: return $this->predicate;
62: }
63:
64:
65: public function relationships() {
66: $relationships = array();
67: foreach($this->schema->listRelationships() as $name => $prop) {
68: $relationships[] = $this->{$name};
69: }
70:
71: return $relationships;
72: }
73:
74:
75: public function where() {
76: return Query::ORM($this)->where(func_get_args());
77: }
78: }
79: