1: <?php
2:
3: namespace PHPixie\ORM;
4:
5: class Builder
6: {
7: /**
8: * @type \PHPixie\Database
9: */
10: protected $database;
11: protected $configSlice;
12: protected $wrappers;
13:
14: protected $instances = array();
15:
16: public function __construct($database, $configSlice, $wrappers = null)
17: {
18: $this->database = $database;
19: $this->configSlice = $configSlice;
20: $this->wrappers = $wrappers;
21: }
22:
23: /**
24: * @return Conditions
25: */
26: public function conditions()
27: {
28: return $this->instance('conditions');
29: }
30:
31: /**
32: * @return Configs
33: */
34: public function configs()
35: {
36: return $this->instance('configs');
37: }
38:
39: /**
40: * @return Data
41: */
42: public function data()
43: {
44: return $this->instance('data');
45: }
46:
47: /**
48: * @return Database
49: */
50: public function database()
51: {
52: return $this->instance('database');
53: }
54:
55: /**
56: * @return Drivers
57: */
58: public function drivers()
59: {
60: return $this->instance('drivers');
61: }
62:
63: /**
64: * @return Loaders
65: */
66: public function loaders()
67: {
68: return $this->instance('loaders');
69: }
70:
71: /**
72: * @return Mappers
73: */
74: public function mappers()
75: {
76: return $this->instance('mappers');
77: }
78:
79: /**
80: * @return Maps
81: */
82: public function maps() {
83: return $this->instance('maps');
84: }
85:
86: /**
87: * @return Models
88: */
89: public function models()
90: {
91: return $this->instance('models');
92: }
93:
94: /**
95: * @return Planners
96: */
97: public function planners()
98: {
99: return $this->instance('planners');
100: }
101:
102: /**
103: * @return Plans
104: */
105: public function plans()
106: {
107: return $this->instance('plans');
108: }
109:
110: /**
111: * @return Relationships
112: */
113: public function relationships()
114: {
115: return $this->instance('relationships');
116: }
117:
118: /**
119: * @return Repositories
120: */
121: public function repositories()
122: {
123: return $this->instance('repositories');
124: }
125:
126: /**
127: * @return Steps
128: */
129: public function steps()
130: {
131: return $this->instance('steps');
132: }
133:
134: /**
135: * @return Values
136: */
137: public function values()
138: {
139: return $this->instance('values');
140: }
141:
142: protected function instance($name)
143: {
144: if(!array_key_exists($name, $this->instances)) {
145: $method = 'build'.ucfirst($name);
146: $this->instances[$name] = $this->$method();
147: }
148:
149: return $this->instances[$name];
150: }
151:
152: protected function buildConditions()
153: {
154: return new Conditions($this);
155: }
156:
157: protected function buildConfigs()
158: {
159: return new Configs();
160: }
161:
162: protected function buildData()
163: {
164: return new Data();
165: }
166:
167: protected function buildDatabase()
168: {
169: return new Database($this->database);
170: }
171:
172: protected function buildDrivers()
173: {
174: return new Drivers($this);
175: }
176:
177: protected function buildLoaders()
178: {
179: return new Loaders($this);
180: }
181:
182: protected function buildMappers()
183: {
184: return new Mappers($this);
185: }
186:
187: protected function buildMaps() {
188: return new Maps(
189: $this,
190: $this->configSlice->slice('relationships')
191: );
192: }
193:
194: protected function buildModels()
195: {
196: return new Models(
197: $this,
198: $this->configSlice->slice('models'),
199: $this->wrappers
200: );
201: }
202:
203: protected function buildPlanners()
204: {
205: return new Planners($this);
206: }
207:
208: protected function buildPlans()
209: {
210: return new Plans();
211: }
212:
213: protected function buildRelationships()
214: {
215: return new Relationships($this);
216: }
217:
218: protected function buildRepositories()
219: {
220: return new Repositories($this->models());
221: }
222:
223: protected function buildSteps()
224: {
225: return new Steps($this);
226: }
227:
228: protected function buildValues()
229: {
230: return new Values();
231: }
232: }
233: