13
13
14
14
namespace ApiPlatform \Metadata ;
15
15
16
+ use ApiPlatform \Metadata \Exception \RuntimeException ;
17
+
16
18
/**
17
19
* A parameter dictionnary.
18
20
*
@@ -53,7 +55,7 @@ public function getIterator(): \Traversable
53
55
public function add (string $ key , Parameter $ value ): self
54
56
{
55
57
foreach ($ this ->parameters as $ i => [$ parameterName , $ parameter ]) {
56
- if ($ parameterName === $ key ) {
58
+ if ($ parameterName === $ key && $ value ::class === $ parameter ::class ) {
57
59
$ this ->parameters [$ i ] = [$ key , $ value ];
58
60
59
61
return $ this ;
@@ -65,34 +67,43 @@ public function add(string $key, Parameter $value): self
65
67
return $ this ;
66
68
}
67
69
68
- public function get (string $ key ): ?Parameter
70
+ /**
71
+ * @param class-string $parameterClass
72
+ */
73
+ public function remove (string $ key , string $ parameterClass ): self
69
74
{
70
75
foreach ($ this ->parameters as $ i => [$ parameterName , $ parameter ]) {
71
- if ($ parameterName === $ key ) {
72
- return $ parameter ;
76
+ if ($ parameterName === $ key && $ parameterClass === $ parameter ::class) {
77
+ unset($ this ->parameters [$ i ]);
78
+
79
+ return $ this ;
73
80
}
74
81
}
75
82
76
- return null ;
83
+ throw new RuntimeException ( sprintf ( ' Could not remove parameter "%s". ' , $ key )) ;
77
84
}
78
85
79
- public function remove (string $ key ): self
86
+ /**
87
+ * @param class-string $parameterClass
88
+ */
89
+ public function get (string $ key , string $ parameterClass ): ?Parameter
80
90
{
81
- foreach ($ this ->parameters as $ i => [$ parameterName , $ parameter ]) {
82
- if ($ parameterName === $ key ) {
83
- unset($ this ->parameters [$ i ]);
84
-
85
- return $ this ;
91
+ foreach ($ this ->parameters as [$ parameterName , $ parameter ]) {
92
+ if ($ parameterName === $ key && $ parameterClass === $ parameter ::class) {
93
+ return $ parameter ;
86
94
}
87
95
}
88
96
89
- throw new \ RuntimeException ( sprintf ( ' Could not remove parameter "%s". ' , $ key )) ;
97
+ return null ;
90
98
}
91
99
92
- public function has (string $ key ): bool
100
+ /**
101
+ * @param class-string $parameterClass
102
+ */
103
+ public function has (string $ key , string $ parameterClass ): bool
93
104
{
94
- foreach ($ this ->parameters as $ i => [$ parameterName , $ parameter ]) {
95
- if ($ parameterName === $ key ) {
105
+ foreach ($ this ->parameters as [$ parameterName , $ parameter ]) {
106
+ if ($ parameterName === $ key && $ parameterClass === $ parameter ::class ) {
96
107
return true ;
97
108
}
98
109
}
0 commit comments