WP_CLI\Utils
phar_safe_path()
Get a Phar-safe version of a path.
For paths inside a Phar, this strips the outer filesystem's location to reduce the path to what it needs to be within the Phar archive.
Use the __FILE__ or __DIR__ constants as a starting point.
No Hooks.
Returns
String. A Phar-safe version of the path.
Usage
phar_safe_path( $path );
- $path(string) (required)
- An absolute path that might be within a Phar.
phar_safe_path() phar safe path code WP-CLI 2.13.0-alpha
function phar_safe_path( $path ) {
if ( ! inside_phar() ) {
return $path;
}
return str_replace(
PHAR_STREAM_PREFIX . rtrim( WP_CLI_PHAR_PATH, '/' ) . '/',
PHAR_STREAM_PREFIX,
$path
);
}