1919use Tempest \Support \Regex ;
2020use Tempest \Support \Str ;
2121
22+ use function Tempest \Support \path ;
2223use function Tempest \Support \str ;
2324
2425final class UriGenerator
@@ -41,7 +42,7 @@ public function hasValidSignature(Request $request): bool
4142 return false ;
4243 }
4344
44- if ($ expiresAt !== null && is_numeric ($ expiresAt ) && DateTime::fromTimestamp ((int ) $ expiresAt )->isPast ()) {
45+ if ($ expiresAt !== null && is_numeric ($ expiresAt ) && DateTime::fromTimestamp ((int )$ expiresAt )->isPast ()) {
4546 return false ;
4647 }
4748
@@ -74,7 +75,7 @@ public function createTemporarySignedUri(array|string|MethodReflector $action, D
7475 }
7576
7677 if ($ duration instanceof Duration) {
77- $ duration = DateTime::now ()->plusMilliseconds ((int ) $ duration ->getTotalMilliseconds ());
78+ $ duration = DateTime::now ()->plusMilliseconds ((int )$ duration ->getTotalMilliseconds ());
7879 }
7980
8081 return $ this ->createSignedUri ($ uri , ...[
@@ -149,7 +150,7 @@ public function createUri(array|string|MethodReflector $action, mixed ...$params
149150
150151 $ uri = $ uri ->replaceRegex (
151152 regex: '#\{ ' . $ key . DiscoveredRoute::ROUTE_PARAM_CUSTOM_REGEX . '\}# ' ,
152- replace: (string ) $ value ,
153+ replace: (string )$ value ,
153154 );
154155 }
155156
@@ -206,14 +207,24 @@ private function normalizeActionToUri(array|string|MethodReflector $action): str
206207
207208 [$ controllerClass , $ controllerMethod ] = is_array ($ action ) ? $ action : [$ action , '__invoke ' ];
208209
209- $ routeAttribute = new ClassReflector ($ controllerClass )
210- -> getMethod ( $ controllerMethod )
211- ->getAttribute (Route::class);
210+ $ method = new ClassReflector ($ controllerClass )-> getMethod ( $ controllerMethod );
211+
212+ $ routeAttribute = $ method ->getAttribute (Route::class);
212213
213214 if ($ routeAttribute === null ) {
214215 throw new ControllerMethodHadNoRouteAttribute ($ controllerClass , $ controllerMethod );
215216 }
216217
217- return Str \ensure_starts_with ($ routeAttribute ->uri , '/ ' );
218+ $ parts = array_map (
219+ fn (Prefix $ prefix ) => $ prefix ->prefix ,
220+ array_filter ([
221+ $ method ->getDeclaringClass ()->getAttribute (Prefix::class),
222+ $ method ->getAttribute (Prefix::class),
223+ ]),
224+ );
225+
226+ $ parts [] = $ routeAttribute ->uri ;
227+
228+ return Str \ensure_starts_with (path (...$ parts )->toString (), '/ ' );
218229 }
219230}
0 commit comments