1: <?php
2:
3: namespace PHPixie\HTTP\Messages\Message\Request;
4:
5: use Psr\Http\Message\ServerRequestInterface;
6:
7: /**
8: * Base PSR-7 ServerRequest
9: */
10: abstract class ServerRequest extends \PHPixie\HTTP\Messages\Message\Request
11: implements ServerRequestInterface
12: {
13: /**
14: * @var array
15: */
16: protected $serverParams;
17:
18: /**
19: * @var array
20: */
21: protected $queryParams;
22:
23: /**
24: * @var mixed
25: */
26: protected $parsedBody;
27:
28: /**
29: * @var array
30: */
31: protected $cookieParams;
32:
33: /**
34: * @var array
35: */
36: protected $uploadedFiles;
37:
38: /**
39: * @var array
40: */
41: protected $attributes = array();
42:
43: /**
44: * @inheritdoc
45: */
46: public function getServerParams()
47: {
48: $this->requireServerParams();
49: return $this->serverParams;
50: }
51:
52: /**
53: * @inheritdoc
54: */
55: public function getUploadedFiles()
56: {
57: $this->requireUploadedFiles();
58: return $this->uploadedFiles;
59: }
60:
61: /**
62: * @inheritdoc
63: */
64: public function getCookieParams()
65: {
66: return $this->cookieParams;
67: }
68:
69: /**
70: * @inheritdoc
71: */
72: public function withCookieParams(array $cookies)
73: {
74: $new = clone $this;
75: $new->cookieParams = $cookies;
76: return $new;
77: }
78:
79: /**
80: * @inheritdoc
81: */
82: public function getQueryParams()
83: {
84: return $this->queryParams;
85: }
86:
87: /**
88: * @inheritdoc
89: */
90: public function withQueryParams(array $query)
91: {
92: $new = clone $this;
93: $new->queryParams = $query;
94: return $new;
95: }
96:
97: /**
98: * @inheritdoc
99: */
100: public function getParsedBody()
101: {
102: return $this->parsedBody;
103: }
104:
105: /**
106: * @inheritdoc
107: */
108: public function withParsedBody($data)
109: {
110: $new = clone $this;
111: $new->parsedBody = $data;
112: return $new;
113: }
114:
115: /**
116: * @inheritdoc
117: */
118: public function withUploadedFiles(array $uploadedFiles)
119: {
120: $new = clone $this;
121: $new->uploadedFiles = $uploadedFiles;
122: return $new;
123: }
124:
125: /**
126: * @inheritdoc
127: */
128: public function getAttributes()
129: {
130: return $this->attributes;
131: }
132:
133: /**
134: * @inheritdoc
135: */
136: public function getAttribute($attribute, $default = null)
137: {
138: if (!array_key_exists($attribute, $this->attributes)) {
139: return $default;
140: }
141: return $this->attributes[$attribute];
142: }
143:
144: /**
145: * @inheritdoc
146: */
147: public function withAttribute($attribute, $value)
148: {
149: $new = clone $this;
150: $new->attributes[$attribute] = $value;
151: return $new;
152: }
153:
154: /**
155: * @inheritdoc
156: */
157: public function withoutAttribute($attribute)
158: {
159: $new = clone $this;
160: if(array_key_exists($attribute, $new->attributes)) {
161: unset($new->attributes[$attribute]);
162: }
163: return $new;
164: }
165:
166: /**
167: * @return void
168: */
169: protected function requireServerParams()
170: {
171:
172: }
173:
174: /**
175: * @return void
176: */
177: protected function requireUploadedFiles()
178: {
179:
180: }
181:
182: }