17
17
use ArrayAccess ;
18
18
use BadMethodCallException ;
19
19
use Cake \Core \Configure ;
20
- use Cake \Http \ServerRequestFactory ;
21
20
use Cake \Network \Exception \MethodNotAllowedException ;
22
21
use Cake \Network \Session ;
23
22
use Cake \Utility \Hash ;
@@ -62,7 +61,7 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
62
61
public $ data = [];
63
62
64
63
/**
65
- * Array of querystring arguments
64
+ * Array of query string arguments
66
65
*
67
66
* @var array
68
67
* @deprecated 3.4.0 This public property will be removed in 4.0.0. Use getQuery() or getQueryParams() instead.
@@ -305,7 +304,7 @@ protected function _setConfig($config)
305
304
}
306
305
307
306
// Extract a query string from config[url] if present.
308
- // This is required for backwards compatbility and keeping
307
+ // This is required for backwards compatibility and keeping
309
308
// UriInterface implementations happy.
310
309
$ querystr = '' ;
311
310
if (strpos ($ config ['url ' ], '? ' ) !== false ) {
@@ -383,7 +382,7 @@ protected function _processPost($data)
383
382
*
384
383
* @param array $query The array to which the parsed keys/values are being added.
385
384
* @param string $queryString A query string from the URL if provided
386
- * @return array An array containing the parsed querystring keys/values.
385
+ * @return array An array containing the parsed query string as keys/values.
387
386
*/
388
387
protected function _processGet ($ query , $ queryString = '' )
389
388
{
@@ -564,7 +563,7 @@ public function referer($local = false)
564
563
$ base = Configure::read ('App.fullBaseUrl ' ) . $ this ->webroot ;
565
564
if (!empty ($ ref ) && !empty ($ base )) {
566
565
if ($ local && strpos ($ ref , $ base ) === 0 ) {
567
- $ ref = substr ($ ref , strlen ($ base ));
566
+ $ ref = substr ($ ref , strlen ($ base ));
568
567
if (!strlen ($ ref )) {
569
568
$ ref = '/ ' ;
570
569
}
@@ -916,7 +915,7 @@ public function addPaths(array $paths)
916
915
}
917
916
918
917
/**
919
- * Get the value of the current requests URL. Will include querystring arguments.
918
+ * Get the value of the current requests URL. Will include the query string arguments.
920
919
*
921
920
* @param bool $base Include the base path, set to false to trim the base path off.
922
921
* @return string The current request URL including query string args.
@@ -979,6 +978,7 @@ public function header($name)
979
978
* the headers.
980
979
*
981
980
* @return array An associative array of headers and their values.
981
+ * @link http://www.php-fig.org/psr/psr-7/ This method is part of the PSR-7 server request interface.
982
982
*/
983
983
public function getHeaders ()
984
984
{
@@ -1006,6 +1006,7 @@ public function getHeaders()
1006
1006
*
1007
1007
* @param string $name The header you want to get (case-insensitive)
1008
1008
* @return bool Whether or not the header is defined.
1009
+ * @link http://www.php-fig.org/psr/psr-7/ This method is part of the PSR-7 server request interface.
1009
1010
*/
1010
1011
public function hasHeader ($ name )
1011
1012
{
@@ -1023,6 +1024,7 @@ public function hasHeader($name)
1023
1024
* @param string $name The header you want to get (case-insensitive)
1024
1025
* @return array An associative array of headers and their values.
1025
1026
* If the header doesn't exist, an empty array will be returned.
1027
+ * @link http://www.php-fig.org/psr/psr-7/ This method is part of the PSR-7 server request interface.
1026
1028
*/
1027
1029
public function getHeader ($ name )
1028
1030
{
@@ -1039,6 +1041,7 @@ public function getHeader($name)
1039
1041
*
1040
1042
* @param string $name The header you want to get (case-insensitive)
1041
1043
* @return string Header values collapsed into a comma separated string.
1044
+ * @link http://www.php-fig.org/psr/psr-7/ This method is part of the PSR-7 server request interface.
1042
1045
*/
1043
1046
public function getHeaderLine ($ name )
1044
1047
{
@@ -1053,6 +1056,7 @@ public function getHeaderLine($name)
1053
1056
* @param string $name The header name.
1054
1057
* @param string|array $value The header value
1055
1058
* @return static
1059
+ * @link http://www.php-fig.org/psr/psr-7/ This method is part of the PSR-7 server request interface.
1056
1060
*/
1057
1061
public function withHeader ($ name , $ value )
1058
1062
{
@@ -1072,6 +1076,7 @@ public function withHeader($name, $value)
1072
1076
* @param string $name The header name.
1073
1077
* @param string|array $value The header value
1074
1078
* @return static
1079
+ * @link http://www.php-fig.org/psr/psr-7/ This method is part of the PSR-7 server request interface.
1075
1080
*/
1076
1081
public function withAddedHeader ($ name , $ value )
1077
1082
{
@@ -1092,6 +1097,7 @@ public function withAddedHeader($name, $value)
1092
1097
*
1093
1098
* @param string $name The header name to remove.
1094
1099
* @return static
1100
+ * @link http://www.php-fig.org/psr/psr-7/ This method is part of the PSR-7 server request interface.
1095
1101
*/
1096
1102
public function withoutHeader ($ name )
1097
1103
{
@@ -1125,6 +1131,7 @@ public function method()
1125
1131
* by CakePHP internally, and will effect the result of this method.
1126
1132
*
1127
1133
* @return string The name of the HTTP method used.
1134
+ * @link http://www.php-fig.org/psr/psr-7/ This method is part of the PSR-7 server request interface.
1128
1135
*/
1129
1136
public function getMethod ()
1130
1137
{
@@ -1136,6 +1143,7 @@ public function getMethod()
1136
1143
*
1137
1144
* @param string $method The HTTP method to use.
1138
1145
* @return static A new instance with the updated method.
1146
+ * @link http://www.php-fig.org/psr/psr-7/ This method is part of the PSR-7 server request interface.
1139
1147
*/
1140
1148
public function withMethod ($ method )
1141
1149
{
@@ -1161,16 +1169,19 @@ public function withMethod($method)
1161
1169
* used to create this request.
1162
1170
*
1163
1171
* @return array
1172
+ * @link http://www.php-fig.org/psr/psr-7/ This method is part of the PSR-7 server request interface.
1164
1173
*/
1165
1174
public function getServerParams ()
1166
1175
{
1167
1176
return $ this ->_environment ;
1168
1177
}
1169
1178
1170
1179
/**
1171
- * Get all the query parameters.
1180
+ * Get all the query parameters in accordance to the PSR-7 specifications. To read specific query values
1181
+ * use the alternative getQuery() method.
1172
1182
*
1173
1183
* @return array
1184
+ * @link http://www.php-fig.org/psr/psr-7/ This method is part of the PSR-7 server request interface.
1174
1185
*/
1175
1186
public function getQueryParams ()
1176
1187
{
@@ -1182,6 +1193,7 @@ public function getQueryParams()
1182
1193
*
1183
1194
* @param array $query The query string data to use
1184
1195
* @return static A new instance with the updated query string data.
1196
+ * @link http://www.php-fig.org/psr/psr-7/ This method is part of the PSR-7 server request interface.
1185
1197
*/
1186
1198
public function withQueryParams (array $ query )
1187
1199
{
@@ -1396,7 +1408,7 @@ protected function _parseAcceptWithQualifier($header)
1396
1408
*
1397
1409
* @param string|null $name Query string variable name or null to read all.
1398
1410
* @return string|array|null The value being read
1399
- * @deprecated 3.4.0 Use getQuery() or getQueryParams() and withQueryParams() instead.
1411
+ * @deprecated 3.4.0 Use getQuery() or the PSR-7 getQueryParams() and withQueryParams() methods instead.
1400
1412
*/
1401
1413
public function query ($ name = null )
1402
1414
{
@@ -1410,12 +1422,26 @@ public function query($name = null)
1410
1422
/**
1411
1423
* Read a specific query value or dotted path.
1412
1424
*
1413
- * @param string $name The name or dotted path to the query param.
1414
- * @param mixed $default The default value if the named parameter is not set.
1425
+ * Developers are encouraged to use getQueryParams() when possible as it is PSR-7 compliant, and this method
1426
+ * is not.
1427
+ *
1428
+ * ### PSR-7 Alternative
1429
+ *
1430
+ * ```
1431
+ * $value = Hash::get($request->getQueryParams(), 'Post.id', null);
1432
+ * ```
1433
+ *
1434
+ * @param string|null $name The name or dotted path to the query param or null to read all.
1435
+ * @param mixed $default The default value if the named parameter is not set, and $name is not null.
1415
1436
* @return null|string|array Query data.
1437
+ * @see ServerRequest::getQueryParams()
1416
1438
*/
1417
- public function getQuery ($ name , $ default = null )
1439
+ public function getQuery ($ name = null , $ default = null )
1418
1440
{
1441
+ if ($ name === null ) {
1442
+ return $ this ->query ;
1443
+ }
1444
+
1419
1445
return Hash::get ($ this ->query , $ name , $ default );
1420
1446
}
1421
1447
0 commit comments