1: <?php
2:
3: namespace PHPixie\Framework;
4:
5: /**
6: * Base framework factory
7: */
8: abstract class Builder
9: {
10: /**
11: * @var array
12: */
13: protected $instances = array();
14:
15: /**
16: * Assets registry
17: * @return Assets
18: */
19: public function assets()
20: {
21: return $this->instance('assets');
22: }
23:
24: /**
25: * Components factory
26: * @return Components
27: */
28: public function components()
29: {
30: return $this->instance('components');
31: }
32:
33: /**
34: * Context container (e.g. for HTTP context)
35: * @return Context
36: */
37: public function context()
38: {
39: return $this->instance('context');
40: }
41:
42: /**
43: * Extensions registry
44: * @return Extensions
45: */
46: public function extensions()
47: {
48: return $this->instance('extensions');
49: }
50:
51: /**
52: * HTTP handler
53: * @return HTTP
54: */
55: public function http()
56: {
57: return $this->instance('http');
58: }
59:
60: /**
61: * Processors factory
62: * @return Processors
63: */
64: public function processors()
65: {
66: return $this->instance('processors');
67: }
68:
69: /**
70: * @param string $name
71: * @return mixed
72: */
73: protected function instance($name)
74: {
75: if(!array_key_exists($name, $this->instances)) {
76: $method = 'build'.ucfirst($name);
77: $this->instances[$name] = $this->$method();
78: }
79:
80: return $this->instances[$name];
81: }
82:
83: /**
84: * @return Assets
85: */
86: protected function buildAssets()
87: {
88: return new Assets(
89: $this->components()
90: );
91: }
92:
93: /**
94: * @return Components
95: */
96: protected function buildComponents()
97: {
98: return new Components($this);
99: }
100:
101: /**
102: * @return Context
103: */
104: protected function buildContext()
105: {
106: return new Context($this);
107: }
108:
109: /**
110: * @return Extensions
111: */
112: protected function buildExtensions()
113: {
114: return new Extensions($this);
115: }
116:
117: /**
118: * @return HTTP
119: */
120: protected function buildHttp()
121: {
122: return new HTTP($this);
123: }
124:
125: /**
126: * @return Processors
127: */
128: protected function buildProcessors()
129: {
130: return new Processors($this);
131: }
132:
133: /**
134: * Framework Configuration
135: * @return Configuration
136: */
137: abstract public function configuration();
138: }