From 5f48d4d0b088849d1a72ab0dfe11e31ac3ccc2ea Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Fri, 27 Nov 2026 09:55:50 +0000 Subject: [PATCH] Leave psr/log out of the Phar wp-cli/wp-cli#6439 requires composer/xdebug-handler, which pulls in psr/log. Its logger is never set, so psr/log isn't needed at runtime. Leaving it and its autoload map entries out means WP-CLI's autoloader never answers for Psr\Log, so plugins can load their own version (see wp-cli/wp-cli#4632 and #5920). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01UWTd5pwpi2xQfDA6mUYkkx --- utils/make-phar.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/utils/make-phar.php b/utils/make-phar.php index 3b14de5ed..9195b27db 100644 --- a/utils/make-phar.php +++ b/utils/make-phar.php @@ -81,6 +81,7 @@ function add_file( $phar, $path ) { is_dir( WP_CLI_VENDOR_DIR . '/composer/composer' ) ? '\/symfony\/(?:config|console|debug|dependency-injection|event-dispatcher|filesystem|translation|yaml)' : '\/symfony\/', '\/(?:dealerdirect|myclabs|squizlabs|wimg)\/', '\/yoast\/', + '\/psr\/log\/', ]; } else { $strips = [ @@ -96,6 +97,7 @@ function add_file( $phar, $path ) { '\/Composer\/(?:Command\/|Compiler\.php|Console\/|Downloader\/Pear|Installer\/Pear|Question\/|Repository\/Pear|SelfUpdate\/)', '\/(?:dealerdirect|myclabs|squizlabs|wimg)\/', '\/yoast\/', + '\/psr\/log\/', ]; } $strip_res = array_map( @@ -258,7 +260,18 @@ function get_composer_versions( $current_version ) { // for older versions of wp-cli/package-command. Finder errors out on missing directories. $optional_dirs = 'cli' === BUILD ? [ 'seld/cli-prompt' ] - : [ 'psr', 'seld', 'justinrainbow/json-schema', 'marc-mabe/php-enum', 'nikic/php-parser/lib' ]; + : [ 'seld', 'justinrainbow/json-schema', 'marc-mabe/php-enum', 'nikic/php-parser/lib' ]; + +// psr/log only comes in through composer/xdebug-handler, which never calls setLogger(). Leave it +// out (here and from the autoload maps above), so that WP-CLI's autoloader never answers for +// Psr\Log and a plugin can load its own version of it. +if ( 'cli' !== BUILD ) { + foreach ( glob( WP_CLI_VENDOR_DIR . '/psr/*', GLOB_ONLYDIR ) ?: [] as $psr_dir ) { + if ( 'log' !== basename( $psr_dir ) ) { + $optional_dirs[] = 'psr/' . basename( $psr_dir ); + } + } +} foreach ( $optional_dirs as $optional_dir ) { if ( is_dir( WP_CLI_VENDOR_DIR . '/' . $optional_dir ) ) { $finder->in( WP_CLI_VENDOR_DIR . '/' . $optional_dir );