-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
RequestParameters.php
59 lines (48 loc) · 1.36 KB
/
RequestParameters.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php declare(strict_types = 1);
namespace Apitte\Core\Annotation\Controller;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Target;
use Doctrine\Common\Annotations\AnnotationException;
/**
* @Annotation
* @Target("METHOD")
* @NamedArgumentConstructor()
*/
class RequestParameters
{
/** @var RequestParameter[] */
private $parameters = [];
/**
* @param RequestParameter[]|RequestParameter $parameters
*/
public function __construct($parameters)
{
if (empty($parameters)) {
throw new AnnotationException('Empty @RequestParameters given');
}
// Wrap single given request parameter into array
if (!is_array($parameters)) {
$parameters = [$parameters];
}
$takenNames = [];
foreach ($parameters as $parameter) {
if (!isset($takenNames[$parameter->getIn()][$parameter->getName()])) {
$takenNames[$parameter->getIn()][$parameter->getName()] = $parameter;
} else {
throw new AnnotationException(sprintf(
'Multiple @RequestParameter annotations with "name=%s" and "in=%s" given. Each parameter must have unique combination of location and name.',
$parameter->getName(),
$parameter->getIn()
));
}
}
$this->parameters = $parameters;
}
/**
* @return RequestParameter[]
*/
public function getParameters(): array
{
return $this->parameters;
}
}