magicMiddlewareEnricher function
Enricher: emits magicMiddleware: <name1,name2> for the active
route's resolved middleware names.
Uses MagicRouter.currentRoute (added in Plan Step 17 sub-change a)
to reach the RouteDefinition.middlewares list without depending on
any private router state. Middleware names come from the
instance's toString() for MagicMiddleware objects (subclasses
typically use the class name) and the raw string for string aliases.
Returns null when no route is active or the route has zero middlewares.
Implementation
String? magicMiddlewareEnricher(Element element, RefRegistry refs) {
final route = MagicRouter.instance.currentRoute;
if (route == null) return null;
final List<dynamic> middlewares = route.middlewares;
if (middlewares.isEmpty) return null;
final List<String> names = middlewares
.map(_middlewareLabel)
.toList(growable: false);
return 'magicMiddleware: ${names.join(',')}';
}