Each public method of the class a controller file is named after, as a route.
(filePath: string, baseUrl: string, safe: string)
| 113 | |
| 114 | /** Each public method of the class a controller file is named after, as a route. */ |
| 115 | function 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. */ |
| 154 | function awaitedName(handler: string): string { |