WP_CLI\Bootstrap

IncludeRequestsAutoloader::processpublicWP-CLI 1.0

Process this single bootstrapping step.

Method of the class: IncludeRequestsAutoloader{}

No Hooks.

Returns

BootstrapState. Modified state to pass to the next step.

Usage

$IncludeRequestsAutoloader = new IncludeRequestsAutoloader();
$IncludeRequestsAutoloader->process( $state );
$state(BootstrapState) (required)
Contextual state to pass into the step.

IncludeRequestsAutoloader::process() code WP-CLI 2.13.0-alpha

public function process( BootstrapState $state ) {
	// If Requests is already loaded, don't do anything.
	if ( class_exists( RequestsLibrary::CLASS_NAME_V2, false ) || class_exists( RequestsLibrary::CLASS_NAME_V1, false ) ) {
		return $state;
	}

	$runner = new RunnerInstance();

	// 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;
		}
		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(), '/' );
	}

	// 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 ) ) {
			require_once $wp_root . '/wp-includes/Requests/src/Autoload.php';
		}

		if ( class_exists( '\\WpOrg\\Requests\\Autoload' ) ) {
			\WpOrg\Requests\Autoload::register();
			$this->store_requests_meta( RequestsLibrary::CLASS_NAME_V2, self::FROM_WP_CORE );
			return $state;
		}
	}

	// Then see if we can detect the older version bundled with WordPress.
	if ( file_exists( $wp_root . '/wp-includes/class-requests.php' ) ) {
		if ( ! class_exists( '\\Requests', false ) ) {
			require_once $wp_root . '/wp-includes/class-requests.php';
		}

		if ( class_exists( '\\Requests' ) ) {
			\Requests::register_autoloader();
			$this->store_requests_meta( RequestsLibrary::CLASS_NAME_V1, self::FROM_WP_CORE );
			return $state;
		}
	}

	// Finally, fall back to the Requests version bundled with WP-CLI.
	$autoloader = new Autoloader();
	$autoloader->add_namespace(
		'WpOrg\Requests',
		WP_CLI_ROOT . '/bundle/rmccue/requests/src'
	);

	$autoloader->register();

	\WpOrg\Requests\Autoload::register();

	$this->store_requests_meta( RequestsLibrary::CLASS_NAME_V2, self::FROM_WP_CLI );

	return $state;
}