MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / resolveControllerClass

Function resolveControllerClass

src/resolution/frameworks/laravel.ts:645–661  ·  view source on GitHub ↗

The controller class a resource route names: by its path under the controllers root, else by name.

(controller: string, context: ResolutionContext)

Source from the content-addressed store, hash-verified

643
644/** The controller class a resource route names: by its path under the controllers root, else by name. */
645function resolveControllerClass(controller: string, context: ResolutionContext): string | null {
646 // A class the routes file named through its imports: that class, wherever it sits.
647 if (controller.startsWith('\\')) {
648 const named = phpClassesNamed(controller, context);
649 if (named.length > 0) return named[0]!.id;
650 controller = controllerPath(controller);
651 }
652 const rel = controller.replace(/\\/g, '/');
653 const className = rel.split('/').pop()!;
654 const classes = context
655 .getNodesByName(className)
656 .filter((n) => n.kind === 'class' && n.filePath.includes('Controllers'));
657 const suffix = `/${rel.toLowerCase()}.php`;
658 const exact = classes.find((n) => `/${n.filePath.toLowerCase()}`.endsWith(suffix));
659 if (exact) return exact.id;
660 return classes.length === 1 ? classes[0]!.id : null;
661}
662
663/**
664 * Resolve a Controller@method reference: the file the path names under

Callers 1

resolveFunction · 0.85

Calls 3

phpClassesNamedFunction · 0.85
controllerPathFunction · 0.85
getNodesByNameMethod · 0.65

Tested by

no test coverage detected