Skip to content

Commit 48a982d

Browse files
Copilotswissspidy
andcommitted
Use composer patches to fix phar_safe_path in vendor
Removed non-working function override approach. Instead, added cweagans/composer-patches plugin and created a patch file to fix phar_safe_path() in wp-cli/wp-cli vendor code. The patch changes the replacement from bare 'phar://' to 'phar://wp-cli.phar/' alias, ensuring template paths resolve correctly. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 02593d3 commit 48a982d

File tree

5 files changed

+70
-40
lines changed

5 files changed

+70
-40
lines changed

composer.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
},
4242
"require-dev": {
4343
"roave/security-advisories": "dev-latest",
44-
"wp-cli/wp-cli-tests": "^5"
44+
"wp-cli/wp-cli-tests": "^5",
45+
"cweagans/composer-patches": "^1.7"
4546
},
4647
"suggest": {
4748
"psy/psysh": "Enhanced `wp shell` functionality"
@@ -50,7 +51,8 @@
5051
"allow-plugins": {
5152
"dealerdirect/phpcodesniffer-composer-installer": true,
5253
"johnpbloch/wordpress-core-installer": true,
53-
"phpstan/extension-installer": true
54+
"phpstan/extension-installer": true,
55+
"cweagans/composer-patches": true
5456
},
5557
"autoloader-suffix": "WpCliBundle",
5658
"platform": {
@@ -62,6 +64,11 @@
6264
"extra": {
6365
"branch-alias": {
6466
"dev-main": "2.12.x-dev"
67+
},
68+
"patches": {
69+
"wp-cli/wp-cli": {
70+
"Fix phar_safe_path to use alias path": "patches/wp-cli-phar-safe-path.patch"
71+
}
6572
}
6673
},
6774
"autoload-dev": {

composer.lock

Lines changed: 49 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--- a/php/utils.php
2+
+++ b/php/utils.php
3+
@@ -1683,7 +1683,7 @@ function phar_safe_path( $path ) {
4+
}
5+
6+
return str_replace(
7+
PHAR_STREAM_PREFIX . rtrim( WP_CLI_PHAR_PATH, '/' ) . '/',
8+
- PHAR_STREAM_PREFIX,
9+
+ 'phar://wp-cli.phar/',
10+
$path
11+
);
12+
}

php/boot-phar.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,9 @@
1818
if ( file_exists( 'phar://wp-cli.phar/php/wp-cli.php' ) ) {
1919
define( 'WP_CLI_ROOT', 'phar://wp-cli.phar' );
2020
include WP_CLI_ROOT . '/php/wp-cli.php';
21-
// Override phar_safe_path() to fix template resolution (temporary until wp-cli/wp-cli#6242 is merged)
22-
include __DIR__ . '/utils-override.php';
2321
} elseif ( file_exists( 'phar://wp-cli.phar/vendor/wp-cli/wp-cli/php/wp-cli.php' ) ) {
2422
define( 'WP_CLI_ROOT', 'phar://wp-cli.phar/vendor/wp-cli/wp-cli' );
2523
include WP_CLI_ROOT . '/php/wp-cli.php';
26-
// Override phar_safe_path() to fix template resolution (temporary until wp-cli/wp-cli#6242 is merged)
27-
include __DIR__ . '/utils-override.php';
2824
} else {
2925
echo "Couldn't find 'php/wp-cli.php'. Was this Phar built correctly?";
3026
exit( 1 );

php/utils-override.php

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)