@@ -18,31 +18,32 @@ class RoutePath
18
18
];
19
19
20
20
/**
21
+ * @return array<string, string>
21
22
* @throws \ReflectionException
22
23
*/
23
24
public function getPaths (Route $ route ): array
24
25
{
25
- $ paths = $ this ->initAllParametersWithStringType ($ route );
26
+ $ pathParameters = $ this ->initAllParametersWithStringType ($ route );
26
27
27
- $ paths = $ this ->setParameterType ($ route , $ paths );
28
+ $ pathParameters = $ this ->setParameterType ($ route , $ pathParameters );
28
29
29
- $ paths = $ this ->setOptional ($ route , $ paths );
30
+ $ pathParameters = $ this ->setOptional ($ route , $ pathParameters );
30
31
31
- $ paths = $ this ->mutateKeyNameWithBindingField ($ route , $ paths );
32
+ $ pathParameters = $ this ->mutateKeyNameWithBindingField ($ route , $ pathParameters );
32
33
33
- return $ this ->setRegex ($ route , $ paths );
34
+ return $ this ->setRegex ($ route , $ pathParameters );
34
35
}
35
36
36
37
/**
37
38
* Set route path parameter type.
38
- * This method will overwrite `$paths ` type with the real types found from route declaration.
39
+ * This method will overwrite `$pathParameters ` type with the real types found from route declaration.
39
40
*
40
41
* @param \Illuminate\Routing\Route $route
41
- * @param array<string, string> $paths
42
+ * @param array<string, string> $pathParameters
42
43
* @return array<string, string>
43
44
* @throws \ReflectionException
44
45
*/
45
- private function setParameterType (Route $ route , array $ paths ): array
46
+ private function setParameterType (Route $ route , array $ pathParameters ): array
46
47
{
47
48
$ bindableParameters = $ this ->getBindableParameters ($ route );
48
49
@@ -56,7 +57,7 @@ private function setParameterType(Route $route, array $paths): array
56
57
57
58
// For builtin type, always get the type from reflection parameter.
58
59
if ($ bindableParameter ['class ' ] === null ) {
59
- $ paths [$ parameterName ] = $ this ->getParameterType ($ bindableParameter ['parameter ' ]);
60
+ $ pathParameters [$ parameterName ] = $ this ->getParameterType ($ bindableParameter ['parameter ' ]);
60
61
continue ;
61
62
}
62
63
@@ -84,10 +85,10 @@ private function setParameterType(Route $route, array $paths): array
84
85
85
86
// Try set type from model key type.
86
87
if ($ model ->getKeyName () === $ model ->getRouteKeyName ()) {
87
- $ paths [$ parameterName ] = self ::TYPE_MAP [$ model ->getKeyType ()] ?? $ model ->getKeyType ();
88
+ $ pathParameters [$ parameterName ] = self ::TYPE_MAP [$ model ->getKeyType ()] ?? $ model ->getKeyType ();
88
89
}
89
90
}
90
- return $ paths ;
91
+ return $ pathParameters ;
91
92
}
92
93
93
94
private function getOptionalParameterNames (string $ uri ): array
@@ -139,39 +140,39 @@ private function getBindableParameters(Route $route): array
139
140
140
141
/**
141
142
* @param \Illuminate\Routing\Route $route
142
- * @param array<string, string> $paths
143
+ * @param array<string, string> $pathParameters
143
144
* @return array<string, string>
144
145
*/
145
- private function setOptional (Route $ route , array $ paths ): array
146
+ private function setOptional (Route $ route , array $ pathParameters ): array
146
147
{
147
148
$ optionalParameters = $ this ->getOptionalParameterNames ($ route ->uri );
148
149
149
- foreach ($ paths as $ parameter => $ rule ) {
150
+ foreach ($ pathParameters as $ parameter => $ rule ) {
150
151
if (in_array ($ parameter , $ optionalParameters )) {
151
- $ paths [$ parameter ] .= '|nullable ' ;
152
+ $ pathParameters [$ parameter ] .= '|nullable ' ;
152
153
continue ;
153
154
}
154
155
155
- $ paths [$ parameter ] .= '|required ' ;
156
+ $ pathParameters [$ parameter ] .= '|required ' ;
156
157
}
157
- return $ paths ;
158
+ return $ pathParameters ;
158
159
}
159
160
160
161
/**
161
162
* @param \Illuminate\Routing\Route $route
162
- * @param array<string, string> $paths
163
+ * @param array<string, string> $pathParameters
163
164
* @return array<string, string>
164
165
*/
165
- private function setRegex (Route $ route , array $ paths ): array
166
+ private function setRegex (Route $ route , array $ pathParameters ): array
166
167
{
167
- foreach ($ paths as $ parameter => $ rule ) {
168
+ foreach ($ pathParameters as $ parameter => $ rule ) {
168
169
if (!isset ($ route ->wheres [$ parameter ])) {
169
170
continue ;
170
171
}
171
- $ paths [$ parameter ] .= '|regex:/ ' . $ route ->wheres [$ parameter ] . '/ ' ;
172
+ $ pathParameters [$ parameter ] .= '|regex:/ ' . $ route ->wheres [$ parameter ] . '/ ' ;
172
173
}
173
174
174
- return $ paths ;
175
+ return $ pathParameters ;
175
176
}
176
177
177
178
/**
@@ -210,22 +211,22 @@ private function getParameterType(ReflectionParameter $methodParameter): string
210
211
211
212
/**
212
213
* @param \Illuminate\Routing\Route $route
213
- * @param array<string, string> $paths
214
+ * @param array<string, string> $pathParameters
214
215
* @return array<string, string>
215
216
*/
216
- private function mutateKeyNameWithBindingField (Route $ route , array $ paths ): array
217
+ private function mutateKeyNameWithBindingField (Route $ route , array $ pathParameters ): array
217
218
{
218
219
$ mutatedPath = [];
219
220
220
221
foreach ($ route ->parameterNames () as $ name ) {
221
222
$ bindingName = $ route ->bindingFieldFor ($ name );
222
223
223
224
if ($ bindingName === null ) {
224
- $ mutatedPath [$ name ] = $ paths [$ name ];
225
+ $ mutatedPath [$ name ] = $ pathParameters [$ name ];
225
226
continue ;
226
227
}
227
228
228
- $ mutatedPath ["$ name: $ bindingName " ] = $ paths [$ name ];
229
+ $ mutatedPath ["$ name: $ bindingName " ] = $ pathParameters [$ name ];
229
230
}
230
231
231
232
return $ mutatedPath ;
0 commit comments