Skip to main content

Module pathutil

Module pathutil 

Source
Expand description

Exact ports of Composer\Util\Filesystem: normalizePath, findShortestPath, findShortestPathCode (Composer 2.10.3). They decide the paths written into installed.json/installed.php, the autoload files and the bin proxies; checked by tests/oracle_installers.rs. Unix paths only (no C:/file:// prefix).

Functions§

canonicalize
std::fs::canonicalize without the Windows verbatim prefix (\\?\). PHP realpath() (and therefore Composer) returns classic Win32 paths (C:\x), and normalize_path would turn \\?\C:\x into //?/C:/x — a form neither the Win32 APIs nor the paths generated into the autoload files understand. Elsewhere: std::fs::canonicalize as-is.
find_shortest_path
Filesystem::findShortestPath($from, $to, $directories, $preferRelative = false). Both paths must be absolute.
find_shortest_path_code
Filesystem::findShortestPathCode($from, $to, $directories, $staticCode, $preferRelative = false): a PHP expression relative to __DIR__.
is_absolute_path
Filesystem::isAbsolutePath: /…, \…, C:/…/C:\…, or a stream wrapper (phar://…). On Unix only / exists in practice; the starts_with('/') form of the test missed Windows drive-letter paths.
normalize_path
Filesystem::normalizePath: single slashes, ./.. resolution, no trailing slash (except for the root).
php_str
var_export() of a string: single quotes, \ and ' escaped.