Skip to content

Commit ccdb297

Browse files
Copilotswissspidy
andcommitted
Correctly use Phar::running() parameters for path resolution
Use Phar::running(true) for WP_CLI_ROOT (returns phar:// stream path) and Phar::running(false) for WP_CLI_PHAR_PATH (returns filesystem path). This ensures proper path resolution in phar_safe_path() function. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent fecd3fe commit ccdb297

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

php/boot-phar.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,22 @@
99
die( -1 );
1010
}
1111

12-
// Store the path to the Phar early on for `Utils\phar-safe-path()` function.
13-
define( 'WP_CLI_PHAR_PATH', Phar::running( true ) );
12+
// Store the phar stream path for use in determining WP_CLI_ROOT.
13+
// Using Phar::running(true) returns the phar:// stream wrapper path (e.g., phar:///path/to/file.phar)
14+
// which ensures consistent path resolution when the phar is renamed.
15+
$wp_cli_phar_path = Phar::running( true );
1416

15-
// Determine WP_CLI_ROOT dynamically based on the actual phar path
17+
// Store the filesystem path for `Utils\phar_safe_path()` function.
18+
// Using Phar::running(false) returns just the filesystem path without phar:// protocol.
19+
define( 'WP_CLI_PHAR_PATH', Phar::running( false ) );
20+
21+
// Determine WP_CLI_ROOT dynamically based on the actual phar stream path
1622
// instead of hardcoding 'phar://wp-cli.phar' to handle renamed phars.
17-
// Use Phar::running(false) to get the phar stream path (e.g., phar:///path/to/file.phar)
18-
// instead of the filesystem path, ensuring consistency when the phar is renamed.
19-
if ( file_exists( Phar::running( false ) . '/php/wp-cli.php' ) ) {
20-
define( 'WP_CLI_ROOT', Phar::running( false ) );
23+
if ( file_exists( $wp_cli_phar_path . '/php/wp-cli.php' ) ) {
24+
define( 'WP_CLI_ROOT', $wp_cli_phar_path );
2125
include WP_CLI_ROOT . '/php/wp-cli.php';
22-
} elseif ( file_exists( Phar::running( false ) . '/vendor/wp-cli/wp-cli/php/wp-cli.php' ) ) {
23-
define( 'WP_CLI_ROOT', Phar::running( false ) . '/vendor/wp-cli/wp-cli' );
26+
} elseif ( file_exists( $wp_cli_phar_path . '/vendor/wp-cli/wp-cli/php/wp-cli.php' ) ) {
27+
define( 'WP_CLI_ROOT', $wp_cli_phar_path . '/vendor/wp-cli/wp-cli' );
2428
include WP_CLI_ROOT . '/php/wp-cli.php';
2529
} else {
2630
echo "Couldn't find 'php/wp-cli.php'. Was this Phar built correctly?";

0 commit comments

Comments
 (0)