2626 */
2727class Request {
2828
29+ /**
30+ * @var string Request path
31+ */
32+ private $ path ;
33+
2934 /**
3035 * @var string Request URI
3136 */
@@ -121,8 +126,6 @@ public static function headersFromGlobals(array $server) {
121126 * @param array $data
122127 */
123128 public function __construct ($ uri , $ method = 'get ' , $ data = array ()) {
124- $ this ->uri = $ uri ;
125- $ this ->method = strtolower ($ method );
126129
127130 foreach ($ data as $ type => $ values ) {
128131 $ type = strtolower ($ type );
@@ -134,6 +137,17 @@ public function __construct($uri, $method = 'get', $data = array()) {
134137 $ this ->data [$ type ] = $ values ;
135138 }
136139
140+ $ components = parse_url ($ uri );
141+ $ path = $ components ['path ' ] ?: '' ;
142+
143+ parse_str ($ components ['query ' ], $ get );
144+ $ this ->data ['get ' ] = array_merge ($ this ->data ['get ' ], $ get );
145+
146+ $ this ->uri = $ uri ;
147+ $ this ->path = $ path ;
148+ $ this ->method = strtolower ($ method );
149+
150+ $ this ->data ['server ' ]['PATH_INFO ' ] = $ path ;
137151 $ this ->data ['server ' ]['REQUEST_URI ' ] = $ uri ;
138152 $ this ->data ['server ' ]['REQUEST_METHOD ' ] = $ method ;
139153 }
@@ -193,9 +207,18 @@ public function any($key = null) {
193207 }
194208
195209 /**
196- * Retrieve the URI of the Request.
210+ * Retrieve the path of the request.
211+ *
212+ * @return string
213+ */
214+ public function path () {
215+ return $ this ->path ;
216+ }
217+
218+ /**
219+ * Retrieve the URI of the request.
197220 *
198- * @returns string
221+ * @return string
199222 */
200223 public function uri () {
201224 return $ this ->uri ;
@@ -244,7 +267,7 @@ public function hasSession() {
244267 }
245268
246269 /**
247- * Retrieve the session interface for the Request .
270+ * Retrieve the session interface for the request .
248271 *
249272 * @return \Darya\Http\SessionInterface
250273 */
@@ -253,7 +276,7 @@ public function getSession() {
253276 }
254277
255278 /**
256- * Set the session interface for the Request . Starts the session if it
279+ * Set the session interface for the request . Starts the session if it
257280 * hasn't been already.
258281 *
259282 * @param \Darya\Http\SessionInterface $session
@@ -277,7 +300,7 @@ public function flash($key, $values) {
277300 if ($ this ->hasSession ()) {
278301 $ flash = $ this ->session ->get ('flash ' ) ?: array ();
279302
280- foreach ((array )$ values as $ value ) {
303+ foreach ((array ) $ values as $ value ) {
281304 if (!is_null ($ value )) {
282305 $ flash [$ key ][] = $ value ;
283306 }
@@ -293,7 +316,7 @@ public function flash($key, $values) {
293316
294317 /**
295318 * Retrieve and clear flash data with the given key from the session. If no
296- * key is given, all data is retrieved and cleared.
319+ * key is given, all data is retrieved and cleared.
297320 *
298321 * Returns an empty array if this request has no session or flash variables
299322 * were not found with the given key.
0 commit comments