1: <?php
2:
3: namespace PHPixie\Framework;
4:
5: 6: 7:
8: class Components
9: {
10: 11: 12:
13: protected $builder;
14:
15: 16: 17:
18: protected $instances = array();
19:
20: 21: 22:
23: public function __construct($builder)
24: {
25: $this->builder = $builder;
26: }
27:
28: 29: 30: 31:
32: public function slice()
33: {
34: return $this->instance('slice');
35: }
36:
37: 38: 39: 40:
41: public function config()
42: {
43: return $this->instance('config');
44: }
45:
46: 47: 48: 49:
50: public function debug()
51: {
52: return $this->instance('debug');
53: }
54:
55: 56: 57: 58:
59: public function database()
60: {
61: return $this->instance('database');
62: }
63:
64: 65: 66: 67:
68: public function filesystem()
69: {
70: return $this->instance('filesystem');
71: }
72:
73: 74: 75: 76:
77: public function http()
78: {
79: return $this->instance('http');
80: }
81:
82: 83: 84: 85:
86: public function httpProcessors()
87: {
88: return $this->instance('httpProcessors');
89: }
90:
91: 92: 93: 94:
95: public function orm()
96: {
97: return $this->instance('orm');
98: }
99:
100: 101: 102: 103:
104: public function processors()
105: {
106: return $this->instance('processors');
107: }
108:
109: 110: 111: 112:
113: public function template()
114: {
115: return $this->instance('template');
116: }
117:
118: 119: 120: 121:
122: public function route()
123: {
124: return $this->instance('route');
125: }
126:
127: 128: 129: 130:
131: public function security()
132: {
133: return $this->instance('security');
134: }
135:
136: 137: 138: 139:
140: public function auth()
141: {
142: return $this->instance('auth');
143: }
144:
145: 146: 147: 148:
149: public function authProcessors()
150: {
151: return $this->instance('authProcessors');
152: }
153:
154: 155: 156: 157:
158: public function paginate()
159: {
160: return $this->instance('paginate');
161: }
162:
163: 164: 165: 166:
167: public function paginateOrm()
168: {
169: return $this->instance('paginateOrm');
170: }
171:
172: 173: 174: 175:
176: public function validate()
177: {
178: return $this->instance('validate');
179: }
180:
181: 182: 183: 184:
185: protected function instance($name)
186: {
187: if(!array_key_exists($name, $this->instances)) {
188: $method = 'build'.ucfirst($name);
189: $this->instances[$name] = $this->$method();
190: }
191:
192: return $this->instances[$name];
193: }
194:
195: 196: 197:
198: protected function buildSlice()
199: {
200: return new \PHPixie\Slice();
201: }
202:
203: 204: 205:
206: protected function buildConfig()
207: {
208: return new \PHPixie\Config(
209: $this->slice()
210: );
211: }
212:
213: 214: 215:
216: protected function buildDebug()
217: {
218: return new \PHPixie\Debug();
219: }
220:
221: 222: 223:
224: protected function buildDatabase()
225: {
226: return new \PHPixie\Database(
227: $this->configuration()->databaseConfig()
228: );
229: }
230:
231: 232: 233:
234: protected function buildOrm()
235: {
236: $configuration = $this->builder->configuration();
237:
238: return new \PHPixie\ORM(
239: $this->database(),
240: $configuration->ormConfig(),
241: $configuration->ormWrappers()
242: );
243: }
244:
245: 246: 247:
248: protected function buildFilesystem()
249: {
250: return new \PHPixie\Filesystem();
251: }
252:
253: 254: 255:
256: protected function buildTemplate()
257: {
258: $configuration = $this->builder->configuration();
259: $extensions = $this->builder->extensions();
260:
261: return new \PHPixie\Template(
262: $this->slice(),
263: $configuration->templateLocator(),
264: $configuration->templateConfig(),
265: $configuration->filesystemRoot(),
266: $extensions->templateExtensions(),
267: $extensions->templateFormats()
268: );
269: }
270:
271: 272: 273:
274: protected function buildHttp()
275: {
276: return new \PHPixie\HTTP(
277: $this->slice()
278: );
279: }
280:
281: 282: 283:
284: protected function buildHttpProcessors()
285: {
286: return new \PHPixie\HTTPProcessors(
287: $this->http()
288: );
289: }
290:
291: 292: 293:
294: protected function buildAuthProcessors()
295: {
296: return new \PHPixie\AuthProcessors(
297: $this->auth()
298: );
299: }
300:
301: 302: 303:
304: protected function buildProcessors()
305: {
306: return new \PHPixie\Processors();
307: }
308:
309: 310: 311:
312: protected function buildRoute()
313: {
314: return new \PHPixie\Route();
315: }
316:
317: 318: 319:
320: protected function buildSecurity()
321: {
322: return new \PHPixie\Security(
323: $this->database()
324: );
325: }
326:
327: 328: 329:
330: protected function buildAuth()
331: {
332: $configuration = $this->configuration();
333:
334: return new \PHPixie\Auth(
335: $configuration->authConfig(),
336: $configuration->authRepositories(),
337: $this->builder->extensions()->authProviderBuilders(),
338: $this->builder->context()
339: );
340: }
341:
342: 343: 344:
345: protected function buildPaginate()
346: {
347: return new \PHPixie\Paginate();
348: }
349:
350: 351: 352:
353: protected function buildPaginateOrm()
354: {
355: return new \PHPixie\PaginateORM(
356: $this->paginate()
357: );
358: }
359:
360: 361: 362:
363: protected function buildValidate()
364: {
365: return new \PHPixie\Validate();
366: }
367:
368: 369: 370:
371: protected function configuration()
372: {
373: return $this->builder->configuration();
374: }
375:
376: }
377: