MCPcopy
hub / github.com/colbymchenry/codegraph / resolvePhpIncludePath

Function resolvePhpIncludePath

src/resolution/import-resolver.ts:557–572  ·  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

555 * modeled. Callers pass an already-extracted static literal path.
556 */
557function resolvePhpIncludePath(
558 includePath: string,
559 fromFile: string,
560 context: ResolutionContext
561): string | null {
562 const projectRoot = context.getProjectRoot();
563 const fromDir = path.dirname(path.join(projectRoot, fromFile));
564 const basePath = path.resolve(fromDir, includePath);
565 const relativePath = path.relative(projectRoot, basePath).replace(/\\/g, '/');
566 if (context.fileExists(relativePath)) return relativePath;
567 // The literal may omit the .php extension (e.g. include "config").
568 for (const ext of EXTENSION_RESOLUTION.php ?? []) {
569 if (context.fileExists(relativePath + ext)) return relativePath + ext;
570 }
571 return null;
572}
573
574/**
575 * Extract import mappings from a file

Callers 1

resolveViaImportFunction · 0.85

Calls 4

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

Tested by

no test coverage detected