1: <?php
2:
3: namespace PHPixie\HTTP;
4:
5: use PHPixie\Slice;
6:
7: 8: 9:
10: class Builder
11: {
12: 13: 14:
15: protected $slice;
16:
17: 18: 19:
20: protected $instances = array();
21:
22: 23: 24: 25:
26: public function __construct($slice) {
27: $this->slice = $slice;
28: }
29:
30: 31: 32: 33:
34: public function messages()
35: {
36: return $this->instance('messages');
37: }
38:
39: 40: 41: 42:
43: public function responses()
44: {
45: return $this->instance('responses');
46: }
47:
48: 49: 50: 51:
52: public function output()
53: {
54: return $this->instance('output');
55: }
56:
57: 58: 59: 60: 61:
62: public function request($serverRequest)
63: {
64: return new Request($this, $serverRequest);
65: }
66:
67: 68: 69: 70: 71:
72: public function data($array = array())
73: {
74: return $this->slice->arrayData($array);
75: }
76:
77: 78: 79: 80: 81:
82: public function headers($headerArray = array())
83: {
84: return new Data\Headers($headerArray);
85: }
86:
87: 88: 89: 90: 91:
92: public function editableHeaders($headerArray = array())
93: {
94: return new Data\Headers\Editable($headerArray);
95: }
96:
97: 98: 99: 100: 101:
102: public function serverData($serverData = array())
103: {
104: return new Data\Server($serverData);
105: }
106:
107: 108: 109: 110: 111: 112: 113:
114: public function context($request, $cookies, $session)
115: {
116: return new Context($request, $cookies, $session);
117: }
118:
119: 120: 121: 122: 123:
124: public function cookies($cookieArray = array())
125: {
126: return new Context\Cookies($this, $cookieArray);
127: }
128:
129: 130: 131: 132:
133: public function sapiSession()
134: {
135: return new Context\Session\SAPI();
136: }
137:
138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148:
149: public function cookiesUpdate(
150: $name,
151: $value,
152: $expires = null,
153: $path = '/',
154: $domain = null,
155: $secure = false,
156: $httpOnly = false
157: )
158: {
159: return new Context\Cookies\Update(
160: $name,
161: $value,
162: $expires,
163: $path,
164: $domain,
165: $secure,
166: $httpOnly
167: );
168: }
169:
170: 171: 172: 173: 174:
175: public function contextContainer($context)
176: {
177: return new Context\Container\Implementation($context);
178: }
179:
180: 181: 182: 183:
184: protected function instance($name)
185: {
186: if(!array_key_exists($name, $this->instances)) {
187: $method = 'build'.ucfirst($name);
188: $this->instances[$name] = $this->$method();
189: }
190:
191: return $this->instances[$name];
192: }
193:
194: 195: 196:
197: protected function buildMessages()
198: {
199: return new Messages();
200: }
201:
202: 203: 204:
205: protected function buildResponses()
206: {
207: return new Responses($this);
208: }
209:
210: 211: 212:
213: protected function buildOutput()
214: {
215: return new Output();
216: }
217: }