Skip to content

Commit 2a4e145

Browse files
committed
Change requestName to key and add entry on annotations reference
1 parent 6fbeb89 commit 2a4e145

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

Controller/Annotations/Param.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ abstract class Param
2222
/** @var string */
2323
public $name;
2424
/** @var string */
25-
public $requestName = null;
25+
public $key = null;
2626
/** @var string */
2727
public $requirements = '';
2828
/** @var mixed */
@@ -35,4 +35,12 @@ abstract class Param
3535
public $array = false;
3636
/** @var boolean */
3737
public $nullable = false;
38+
39+
/**
40+
* @return string
41+
*/
42+
public function getKey()
43+
{
44+
return $this->key ?: $this->name;
45+
}
3846
}

Request/ParamFetcher.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,10 @@ public function get($name, $strict = null)
9494
$strict = $config->strict;
9595
}
9696

97-
$requestName = $config->requestName ? $config->requestName : $config->name;
9897
if ($config instanceof RequestParam) {
99-
$param = $this->request->request->get($requestName, $default);
98+
$param = $this->request->request->get($config->getKey(), $default);
10099
} elseif ($config instanceof QueryParam) {
101-
$param = $this->request->query->get($requestName, $default);
100+
$param = $this->request->query->get($config->getKey(), $default);
102101
} else {
103102
$param = null;
104103
}

Resources/doc/annotations-reference.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use FOS\RestBundle\Controller\Annotations\QueryParam;
1111
/**
1212
* @QueryParam(
1313
* name="",
14+
* key=null,
1415
* requirements="",
1516
* default=null,
1617
* description="",
@@ -29,6 +30,7 @@ use FOS\RestBundle\Controller\Annotations\RequestParam;
2930
/**
3031
* @RequestParam(
3132
* name="",
33+
* key=null,
3234
* requirements="",
3335
* default=null,
3436
* description="",

Tests/Request/ParamFetcherTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function setup()
7676

7777
$annotations['biz'] = new QueryParam;
7878
$annotations['biz']->name = 'biz';
79-
$annotations['biz']->requestName = 'business';
79+
$annotations['biz']->key = 'business';
8080
$annotations['biz']->requirements = '\d+';
8181
$annotations['biz']->default = null;
8282
$annotations['biz']->nullable = true;
@@ -332,7 +332,7 @@ public function testExceptionOnNonConfiguredParameter()
332332
$queryFetcher->get('none', '42');
333333
}
334334

335-
public function testRequestName()
335+
public function testKeyPrecedenceOverName()
336336
{
337337
$queryFetcher = $this->getParamFetcher(array('business' => 5));
338338
$queryFetcher->setController($this->controller);

0 commit comments

Comments
 (0)