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

Function conventionRoutes

src/resolution/frameworks/codeigniter.ts:115–151  ·  view source on GitHub ↗

Each public method of the class a controller file is named after, as a route.

(filePath: string, baseUrl: string, safe: string)

Source from the content-addressed store, hash-verified

113
114/** Each public method of the class a controller file is named after, as a route. */
115function conventionRoutes(filePath: string, baseUrl: string, safe: string): { nodes: Node[]; references: UnresolvedRef[] } {
116 const nodes: Node[] = [];
117 const references: UnresolvedRef[] = [];
118 const stem = filePath.slice(filePath.lastIndexOf('/') + 1, -'.php'.length).toLowerCase();
119 CLASS_RE.lastIndex = 0;
120 let cls: RegExpExecArray | null;
121 while ((cls = CLASS_RE.exec(safe)) !== null) {
122 if (cls[2]!.toLowerCase() === stem) break;
123 }
124 if (!cls || /abstract/.test(cls[1]!)) return { nodes, references };
125
126 const now = Date.now();
127 const seen = new Set<string>();
128 METHOD_RE.lastIndex = 0;
129 let m: RegExpExecArray | null;
130 while ((m = METHOD_RE.exec(safe)) !== null) {
131 const name = m[2]!;
132 // A leading underscore is CodeIgniter's own way to keep a method off the web.
133 if (/private|protected/.test(m[1]!) || name.startsWith('_')) continue;
134 const routePath = name.toLowerCase() === 'index' ? baseUrl : `${baseUrl}/${name.toLowerCase()}`;
135 if (seen.has(routePath)) continue;
136 seen.add(routePath);
137 const line = safe.slice(0, m.index).split('\n').length;
138 const route = routeNode(filePath, line, 'ANY', routePath, now);
139 nodes.push(route);
140 references.push({
141 fromNodeId: route.id,
142 referenceName: `${METHOD_REF}${filePath}|${name}`,
143 referenceKind: 'references',
144 line,
145 column: 0,
146 filePath,
147 language: 'php',
148 });
149 }
150 return { nodes, references };
151}
152
153/** The name the handler's method goes by, or its class's when only that is written. */
154function awaitedName(handler: string): string {

Callers 1

extractFunction · 0.85

Calls 5

routeNodeFunction · 0.85
hasMethod · 0.80
pushMethod · 0.80
execMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected