php/WP_CLI/Extractor.php
private static function extract_tarball( $tarball, $dest ) {

		if ( class_exists( 'PharData' ) ) {
			try {
				$phar    = new PharData( $tarball );
				$tempdir = implode(
					DIRECTORY_SEPARATOR,
					array(
						dirname( $tarball ),
						Utils\basename( $tarball, '.tar.gz' ),
						$phar->getFilename(),
					)
				);

				$phar->extractTo( dirname( $tempdir ), null, true );

				self::copy_overwrite_files( $tempdir, $dest );

				self::rmdir( dirname( $tempdir ) );
				return;
			} catch ( \Exception $e ) {
				WP_CLI::warning( "PharData failed, falling back to 'tar xz' (" . $e->getMessage() . ')' );
				// Fall through to trying `tar xz` below
			}
		}
		// Note: directory must exist for tar --directory to work.
		$cmd         = Utils\esc_cmd( 'tar xz --strip-components=1 --directory=%s -f %s', $dest, $tarball );
		$process_run = WP_CLI::launch( $cmd, false /*exit_on_error*/, true /*return_detailed*/ );
		if ( 0 !== $process_run->return_code ) {
			throw new \Exception( sprintf( 'Failed to execute `%s`: %s.', $cmd, self::tar_error_msg( $process_run ) ) );
		}
	}
private static function extract_tarball( $tarball, $dest ) {

		if ( class_exists( 'PharData' ) ) {
			try {
				$phar    = new PharData( $tarball );
				$tempdir = implode(
					DIRECTORY_SEPARATOR,
					array(
						dirname( $tarball ),
						Utils\basename( $tarball, '.tar.gz' ),
						$phar->getFilename(),
					)
				);

				$phar->extractTo( dirname( $tempdir ), null, true );

				self::copy_overwrite_files( $tempdir, $dest );

				self::rmdir( dirname( $tempdir ) );
				return;
			} catch ( \Exception $e ) {
				WP_CLI::warning( "PharData failed, falling back to 'tar xz' (" . $e->getMessage() . ')' );
				// Fall through to trying `tar xz` below
			}
		}
		// Note: directory must exist for tar --directory to work.
		$cmd         = Utils\esc_cmd( 'tar xz --strip-components=1 --directory=%s -f %s', $dest, $tarball );
		$process_run = WP_CLI::launch( $cmd, false /*exit_on_error*/, true /*return_detailed*/ );
		if ( 0 !== $process_run->return_code ) {
			throw new \Exception( sprintf( 'Failed to execute `%s`: %s.', $cmd, self::tar_error_msg( $process_run ) ) );
		}
	}
private static function extract_tarball ( $ tarball , $ dest ) { if ( class_exists ( 'PharData' ) ) { try { $ phar = new PharData ( $ tarball ) ; $ tempdir = implode ( DIRECTORY_SEPARATOR , array ( dirname ( $ tarball ) , Utils \ basename ( $ tarball , '.tar.gz' ) , $ phar -> getFilename ( ) , ) ) ; $ phar -> extractTo ( dirname ( $ tempdir ) , null , true ) ; self :: copy_overwrite_files ( $ tempdir , $ dest ) ; self :: rmdir ( dirname ( $ tempdir ) ) ; return ; } catch ( \ Exception $ e ) { WP_CLI :: warning ( "PharData failed, falling back to 'tar xz' (" . $ e -> getMessage ( ) . ')' ) ; // Fall through to trying `tar xz` below } } // Note: directory must exist for tar --directory to work. $ cmd = Utils \ esc_cmd ( 'tar xz --strip-components=1 --directory=%s -f %s' , $ dest , $ tarball ) ; $ process_run = WP_CLI :: launch ( $ cmd , false /*exit_on_error*/ , true /*return_detailed*/ ) ; if ( 0 !== $ process_run -> return_code ) { throw new \ Exception ( sprintf ( 'Failed to execute `%s`: %s.' , $ cmd , self :: tar_error_msg ( $ process_run ) ) ) ; } }
Extract a tarball to a specific destination.

@param string $tarball
@param string $dest
Extract a tarball to a specific destination .