WP_CLI\Utils

phar_safe_path()WP-CLI 1.0

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.

Return

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() code WP-CLI 2.8.0-alpha

function phar_safe_path( $path ) {

	if ( ! inside_phar() ) {
		return $path;
	}

	return str_replace(
		PHAR_STREAM_PREFIX . WP_CLI_PHAR_PATH . '/',
		PHAR_STREAM_PREFIX,
		$path
	);
}