1: <?php
2:
3: namespace PHPixie\ORM;
4:
5: class Mappers
6: {
7: 8: 9:
10: protected $ormBuilder;
11: protected $instances = array();
12:
13: public function __construct($ormBuilder)
14: {
15: $this->ormBuilder = $ormBuilder;
16: }
17:
18: 19: 20:
21: public function query()
22: {
23: return $this->instance('query');
24: }
25:
26: 27: 28:
29: public function conditions()
30: {
31: return $this->instance('conditions');
32: }
33:
34: 35: 36:
37: public function conditionsNormalizer()
38: {
39: return $this->instance('conditionsNormalizer');
40: }
41:
42: 43: 44:
45: public function conditionsOptimizer()
46: {
47: return $this->instance('conditionsOptimizer');
48: }
49:
50: 51: 52:
53: public function preload()
54: {
55: return $this->instance('preload');
56: }
57:
58: 59: 60:
61: public function update()
62: {
63: return $this->instance('update');
64: }
65:
66: 67: 68:
69: public function cascadeDelete()
70: {
71: return $this->instance('cascadeDelete');
72: }
73:
74: 75: 76:
77: public function cascadePath()
78: {
79: return new \PHPixie\ORM\Mappers\Cascade\Path($this);
80: }
81:
82: protected function instance($name)
83: {
84: if(!array_key_exists($name, $this->instances)) {
85: $method = 'build'.ucfirst($name);
86: $this->instances[$name] = $this->$method();
87: }
88:
89: return $this->instances[$name];
90: }
91:
92: protected function buildQuery()
93: {
94: return new \PHPixie\ORM\Mappers\Query(
95: $this,
96: $this->ormBuilder->loaders(),
97: $this->ormBuilder->models(),
98: $this->ormBuilder->plans(),
99: $this->ormBuilder->steps()
100: );
101: }
102:
103: protected function buildConditions()
104: {
105: return new \PHPixie\ORM\Mappers\Conditions(
106: $this,
107: $this->ormBuilder->planners(),
108: $this->ormBuilder->relationships(),
109: $this->ormBuilder->maps()->relationship()
110: );
111: }
112:
113: protected function buildConditionsOptimizer()
114: {
115: return new \PHPixie\ORM\Mappers\Conditions\Optimizer(
116: $this,
117: $this->ormBuilder->conditions()
118: );
119: }
120:
121: protected function buildConditionsNormalizer()
122: {
123: return new \PHPixie\ORM\Mappers\Conditions\Normalizer(
124: $this->ormBuilder->conditions(),
125: $this->ormBuilder->models()
126: );
127: }
128:
129: protected function buildPreload()
130: {
131: return new \PHPixie\ORM\Mappers\Preload(
132: $this->ormBuilder->relationships(),
133: $this->ormBuilder->maps()->preload()
134: );
135: }
136:
137: protected function buildUpdate()
138: {
139: return new \PHPixie\ORM\Mappers\Update();
140: }
141:
142: protected function buildCascadeDelete()
143: {
144: return new \PHPixie\ORM\Mappers\Cascade\Mapper\Delete(
145: $this,
146: $this->ormBuilder->relationships(),
147: $this->ormBuilder->models(),
148: $this->ormBuilder->planners(),
149: $this->ormBuilder->steps(),
150: $this->ormBuilder->maps()->cascadeDelete()
151: );
152: }
153:
154: }