Skip to content

Commit 4fb790d

Browse files
committed
QueryParam annotation widening
1 parent 5e266a9 commit 4fb790d

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

Controller/Annotations/QueryParam.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Represents a parameter that must be present in GET data.
1616
*
1717
* @Annotation
18-
* @Target("METHOD")
18+
* @Target({"CLASS", "METHOD"})
1919
* @author Alexander <[email protected]>
2020
*/
2121
class QueryParam extends Param

Request/ParamReader.php

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,19 @@ public function read(\ReflectionClass $reflection, $method)
4444
throw new \InvalidArgumentException(sprintf("Class '%s' has no method '%s' method.", $reflection->getName(), $method));
4545
}
4646

47-
return $this->getParamsFromMethod($reflection->getMethod($method));
47+
$methodParams = $this->getParamsFromMethod($reflection->getMethod($method));
48+
$classParams = $this->getParamsFromClass($reflection);
49+
return array_merge($methodParams, $classParams);
4850
}
49-
51+
5052
/**
51-
* {@inheritDoc}
53+
* Fetches parameters from provided annotation array (fetched from annotationReader)
54+
*
55+
* @param array $annotations
56+
* @return \FOS\RestBundle\Controller\Annotations\Param
5257
*/
53-
public function getParamsFromMethod(\ReflectionMethod $method)
58+
private function getParamsFromAnnotationArray(array $annotations)
5459
{
55-
$annotations = $this->annotationReader->getMethodAnnotations($method);
56-
5760
$params = array();
5861
foreach ($annotations as $annotation) {
5962
if ($annotation instanceof Param) {
@@ -63,4 +66,25 @@ public function getParamsFromMethod(\ReflectionMethod $method)
6366

6467
return $params;
6568
}
69+
70+
/**
71+
* {@inheritDoc}
72+
*/
73+
public function getParamsFromMethod(\ReflectionMethod $method)
74+
{
75+
$annotations = $this->annotationReader->getMethodAnnotations($method);
76+
77+
return $this->getParamsFromAnnotationArray($annotations);
78+
}
79+
80+
/**
81+
*
82+
* {@inheritDoc}
83+
*/
84+
public function getParamsFromClass(\ReflectionClass $class)
85+
{
86+
$annotations = $this->annotationReader->getClassAnnotations($class);
87+
88+
return $this->getParamsFromAnnotationArray($annotations);
89+
}
6690
}

Request/ParamReaderInterface.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,12 @@ public function read(\ReflectionClass $reflection, $method);
3737
* @return array Param annotation objects of the method. Indexed by parameter name.
3838
*/
3939
public function getParamsFromMethod(\ReflectionMethod $method);
40+
41+
/**
42+
*
43+
* @param \ReflectionClass $class
44+
*
45+
* @return array Param annotation objects of the class. Indexed by parameter name.
46+
*/
47+
public function getParamsFromClass(\ReflectionClass $class);
4048
}

0 commit comments

Comments
 (0)