Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions features/requests.feature
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,22 @@ Feature: Requests integration with both v1 and v2
"""
Success: Installed 1 of 1 plugins.
"""

Scenario: Current version with WordPress-bundled Request v1 and an alias
Given a WP installation in 'foo'
And I run `wp --path=foo core download --version=5.8 --force`
And a wp-cli.yml file:
"""
@foo:
path: foo
"""

When I try `WP_CLI_RUNTIME_ALIAS='{"@foo":{"path":"foo"}}' wp @foo option get home --debug`
Then STDERR should contain:
"""
Setting RequestsLibrary::$version to v1
"""
And STDERR should contain:
"""
Setting RequestsLibrary::$source to wp-core
"""
31 changes: 23 additions & 8 deletions php/WP_CLI/Bootstrap/IncludeRequestsAutoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use WP_CLI\Autoloader;
use WP_CLI\RequestsLibrary;
use WP_CLI\Utils;

/**
* Class IncludeRequestsAutoloader.
Expand Down Expand Up @@ -48,16 +49,30 @@ public function process( BootstrapState $state ) {

$runner = new RunnerInstance();

// Make sure we don't deal with an invalid `--path` value.
$config = $runner()->config;
if ( isset( $config['path'] ) &&
( is_bool( $config['path'] ) || empty( $config['path'] ) )
) {
return $state;
// Use `--path` from the alias if one is matching.
$alias_path = null;
if ( $runner()->alias
&& isset( $runner()->aliases[ $runner()->alias ]['path'] ) ) {
$alias_path = $runner()->aliases[ $runner()->alias ]['path'];
// Make sure it isn't an invalid value.
if ( is_bool( $alias_path ) || empty( $alias_path ) ) {
return $state;
Comment thread
schlessera marked this conversation as resolved.
}
if ( ! Utils\is_path_absolute( $alias_path ) ) {
$alias_path = getcwd() . '/' . $alias_path;
}
$wp_root = rtrim( $alias_path, '/' );
} else {
// Make sure we don't deal with an invalid `--path` value.
$config = $runner()->config;
if ( isset( $config['path'] ) &&
( is_bool( $config['path'] ) || empty( $config['path'] ) )
) {
return $state;
}
$wp_root = rtrim( $runner()->find_wp_root(), '/' );
}

$wp_root = rtrim( $runner()->find_wp_root(), '/' );

// First try to detect a newer Requests version bundled with WordPress.
if ( file_exists( $wp_root . '/wp-includes/Requests/src/Autoload.php' ) ) {
if ( ! class_exists( '\\WpOrg\\Requests\\Autoload', false ) ) {
Expand Down