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__.
find_shortest_path_with
findShortestPath with $preferRelative: when true, a path that only shares the root with from is still written relative (../../..), which is how a symlinked path package points at its source.
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.
is_normalized_absolute
Filesystem::normalizePath: single slashes, ./.. resolution, no trailing slash (except for the root). True when normalize_path would return path unchanged: absolute, forward slashes only, no empty / . / .. segment, no trailing slash.
normalize_path
normalize_path_cow
normalize_path without the allocation when there is nothing to do — the case of every scanned file (a normalised directory joined to a name).
php_dirname
PHP dirname() on a normalised Unix path. PHP dirname() on a normalised Unix path.
php_str
var_export() of a string: single quotes, \ and ' escaped.