Skip to content

Commit 20ca839

Browse files
author
thinkingmedia
committed
moved RequestTest to ServerRequestTest
1 parent 12e8376 commit 20ca839

File tree

2 files changed

+221
-195
lines changed

2 files changed

+221
-195
lines changed

src/Http/ServerRequest.php

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use ArrayAccess;
1818
use BadMethodCallException;
1919
use Cake\Core\Configure;
20-
use Cake\Http\ServerRequestFactory;
2120
use Cake\Network\Exception\MethodNotAllowedException;
2221
use Cake\Network\Session;
2322
use Cake\Utility\Hash;
@@ -62,7 +61,7 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
6261
public $data = [];
6362

6463
/**
65-
* Array of querystring arguments
64+
* Array of query string arguments
6665
*
6766
* @var array
6867
* @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)
305304
}
306305

307306
// 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
309308
// UriInterface implementations happy.
310309
$querystr = '';
311310
if (strpos($config['url'], '?') !== false) {
@@ -383,7 +382,7 @@ protected function _processPost($data)
383382
*
384383
* @param array $query The array to which the parsed keys/values are being added.
385384
* @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.
387386
*/
388387
protected function _processGet($query, $queryString = '')
389388
{
@@ -564,7 +563,7 @@ public function referer($local = false)
564563
$base = Configure::read('App.fullBaseUrl') . $this->webroot;
565564
if (!empty($ref) && !empty($base)) {
566565
if ($local && strpos($ref, $base) === 0) {
567-
$ref = substr($ref, strlen($base));
566+
$ref = substr($ref, strlen($base));
568567
if (!strlen($ref)) {
569568
$ref = '/';
570569
}
@@ -916,7 +915,7 @@ public function addPaths(array $paths)
916915
}
917916

918917
/**
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.
920919
*
921920
* @param bool $base Include the base path, set to false to trim the base path off.
922921
* @return string The current request URL including query string args.
@@ -979,6 +978,7 @@ public function header($name)
979978
* the headers.
980979
*
981980
* @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.
982982
*/
983983
public function getHeaders()
984984
{
@@ -1006,6 +1006,7 @@ public function getHeaders()
10061006
*
10071007
* @param string $name The header you want to get (case-insensitive)
10081008
* @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.
10091010
*/
10101011
public function hasHeader($name)
10111012
{
@@ -1023,6 +1024,7 @@ public function hasHeader($name)
10231024
* @param string $name The header you want to get (case-insensitive)
10241025
* @return array An associative array of headers and their values.
10251026
* 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.
10261028
*/
10271029
public function getHeader($name)
10281030
{
@@ -1039,6 +1041,7 @@ public function getHeader($name)
10391041
*
10401042
* @param string $name The header you want to get (case-insensitive)
10411043
* @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.
10421045
*/
10431046
public function getHeaderLine($name)
10441047
{
@@ -1053,6 +1056,7 @@ public function getHeaderLine($name)
10531056
* @param string $name The header name.
10541057
* @param string|array $value The header value
10551058
* @return static
1059+
* @link http://www.php-fig.org/psr/psr-7/ This method is part of the PSR-7 server request interface.
10561060
*/
10571061
public function withHeader($name, $value)
10581062
{
@@ -1072,6 +1076,7 @@ public function withHeader($name, $value)
10721076
* @param string $name The header name.
10731077
* @param string|array $value The header value
10741078
* @return static
1079+
* @link http://www.php-fig.org/psr/psr-7/ This method is part of the PSR-7 server request interface.
10751080
*/
10761081
public function withAddedHeader($name, $value)
10771082
{
@@ -1092,6 +1097,7 @@ public function withAddedHeader($name, $value)
10921097
*
10931098
* @param string $name The header name to remove.
10941099
* @return static
1100+
* @link http://www.php-fig.org/psr/psr-7/ This method is part of the PSR-7 server request interface.
10951101
*/
10961102
public function withoutHeader($name)
10971103
{
@@ -1125,6 +1131,7 @@ public function method()
11251131
* by CakePHP internally, and will effect the result of this method.
11261132
*
11271133
* @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.
11281135
*/
11291136
public function getMethod()
11301137
{
@@ -1136,6 +1143,7 @@ public function getMethod()
11361143
*
11371144
* @param string $method The HTTP method to use.
11381145
* @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.
11391147
*/
11401148
public function withMethod($method)
11411149
{
@@ -1161,16 +1169,19 @@ public function withMethod($method)
11611169
* used to create this request.
11621170
*
11631171
* @return array
1172+
* @link http://www.php-fig.org/psr/psr-7/ This method is part of the PSR-7 server request interface.
11641173
*/
11651174
public function getServerParams()
11661175
{
11671176
return $this->_environment;
11681177
}
11691178

11701179
/**
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.
11721182
*
11731183
* @return array
1184+
* @link http://www.php-fig.org/psr/psr-7/ This method is part of the PSR-7 server request interface.
11741185
*/
11751186
public function getQueryParams()
11761187
{
@@ -1182,6 +1193,7 @@ public function getQueryParams()
11821193
*
11831194
* @param array $query The query string data to use
11841195
* @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.
11851197
*/
11861198
public function withQueryParams(array $query)
11871199
{
@@ -1396,7 +1408,7 @@ protected function _parseAcceptWithQualifier($header)
13961408
*
13971409
* @param string|null $name Query string variable name or null to read all.
13981410
* @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.
14001412
*/
14011413
public function query($name = null)
14021414
{
@@ -1410,12 +1422,26 @@ public function query($name = null)
14101422
/**
14111423
* Read a specific query value or dotted path.
14121424
*
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.
14151436
* @return null|string|array Query data.
1437+
* @see ServerRequest::getQueryParams()
14161438
*/
1417-
public function getQuery($name, $default = null)
1439+
public function getQuery($name = null, $default = null)
14181440
{
1441+
if ($name === null) {
1442+
return $this->query;
1443+
}
1444+
14191445
return Hash::get($this->query, $name, $default);
14201446
}
14211447

0 commit comments

Comments
 (0)