WP_CLI\Utils
extract_from_phar()
Extract a file from a Phar archive.
Files that need to be read by external programs have to be extracted from the Phar archive. If the file is not within a Phar archive, the function returns the path unchanged.
No Hooks.
Returns
String. Path to the extracted file.
Usage
extract_from_phar( $path );
- $path(string) (required)
- Path to the file to extract.
extract_from_phar() extract from phar code WP-CLI 2.13.0-alpha
function extract_from_phar( $path ) {
if ( ! inside_phar( $path ) ) {
return $path;
}
$fname = basename( $path );
$tmp_path = get_temp_dir() . uniqid( 'wp-cli-extract-from-phar-', true ) . "-$fname";
copy( $path, $tmp_path );
register_shutdown_function(
function () use ( $tmp_path ) {
if ( file_exists( $tmp_path ) ) {
unlink( $tmp_path );
}
}
);
return $tmp_path;
}