* Resolve a PHP include/require path to a project-relative file path. * * PHP resolves includes relative to the including file's directory (the * common case for procedural codebases); php.ini `include_path` is not * modeled. Callers pass an already-extracted static literal path.
( includePath: string, fromFile: string, context: ResolutionContext )
| 738 | * modeled. Callers pass an already-extracted static literal path. |
| 739 | */ |
| 740 | function resolvePhpIncludePath( |
| 741 | includePath: string, |
| 742 | fromFile: string, |
| 743 | context: ResolutionContext |
| 744 | ): string | null { |
| 745 | const projectRoot = context.getProjectRoot(); |
| 746 | const fromDir = path.dirname(path.join(projectRoot, fromFile)); |
| 747 | const basePath = path.resolve(fromDir, includePath); |
| 748 | const relativePath = path.relative(projectRoot, basePath).replace(/\\/g, '/'); |
| 749 | if (context.fileExists(relativePath)) return relativePath; |
| 750 | // The literal may omit the .php extension (e.g. include "config"). |
| 751 | for (const ext of EXTENSION_RESOLUTION.php ?? []) { |
| 752 | if (context.fileExists(relativePath + ext)) return relativePath + ext; |
| 753 | } |
| 754 | return null; |
| 755 | } |
| 756 | |
| 757 | /** |
| 758 | * Extract import mappings from a file |
no test coverage detected