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

Function resolvePhpIncludePath

src/resolution/import-resolver.ts:1957–1972  ·  view source on GitHub ↗

* 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
)

Source from the content-addressed store, hash-verified

1955 * modeled. Callers pass an already-extracted static literal path.
1956 */
1957function resolvePhpIncludePath(
1958 includePath: string,
1959 fromFile: string,
1960 context: ResolutionContext
1961): string | null {
1962 const projectRoot = context.getProjectRoot();
1963 const fromDir = path.dirname(path.join(projectRoot, fromFile));
1964 const basePath = path.resolve(fromDir, includePath);
1965 const relativePath = path.relative(projectRoot, basePath).replace(/\\/g, '/');
1966 if (context.fileExists(relativePath)) return relativePath;
1967 // The literal may omit the .php extension (e.g. include "config").
1968 for (const ext of EXTENSION_RESOLUTION.php ?? []) {
1969 if (context.fileExists(relativePath + ext)) return relativePath + ext;
1970 }
1971 return null;
1972}
1973
1974/**
1975 * Extract import mappings from a file

Callers 1

resolveViaImportFunction · 0.85

Calls 4

fileExistsMethod · 0.80
getProjectRootMethod · 0.65
resolveMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected