Make WordPress Core


Ignore:
Timestamp:
11/25/2021 01:10:30 AM (4 years ago)
Author:
SergeyBiryukov
Message:

External Libraries: Update the Requests library to version 2.0.0.

This is a major release and contains breaking changes.

Most important changes to be aware of for this release:

  • All code is now namespaced. Though there is a full backward compatibility layer available and the old class names are still supported, using them will generate a deprecation notice (which can be silenced by plugins if they'd need to support multiple WP versions). See the upgrade guide for more details.
  • A lot of classes have been marked final. This should generally not affect userland code as care has been taken to not apply the final keyword to classes which are known to be extended in userland code.
  • Extensive input validation has been added to Requests. When Requests is used as documented though, this will be unnoticable.
  • A new WpOrg\Requests\Requests::has_capabilities() method has been introduced which can be used to address #37708.
  • A new WpOrg\Requests\Response::decode_body() method has been introduced which may be usable to simplify some of the WP native wrapper code.
  • Remaining PHP 8.0 compatibility fixed (support for named parameters).
  • PHP 8.1 compatibility.

Release notes: https://github.com/WordPress/Requests/releases/tag/v2.0.0

For a full list of changes in this update, see the Requests GitHub:
https://github.com/WordPress/Requests/compare/v1.8.1...v2.0.0

Follow-up to [50842], [51078].

Props jrf, schlessera, datagutten, wojsmol, dd32, dustinrue, soulseekah, costdev, szepeviktor.
Fixes #54504.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/Requests/Auth/Basic.php

    r50842 r52244  
    33 * Basic Authentication provider
    44 *
    5  * @package Requests
    6  * @subpackage Authentication
     5 * @package Requests\Authentication
    76 */
     7
     8namespace WpOrg\Requests\Auth;
     9
     10use WpOrg\Requests\Auth;
     11use WpOrg\Requests\Exception\ArgumentCount;
     12use WpOrg\Requests\Exception\InvalidArgument;
     13use WpOrg\Requests\Hooks;
    814
    915/**
     
    1319 * header.
    1420 *
    15  * @package Requests
    16  * @subpackage Authentication
     21 * @package Requests\Authentication
    1722 */
    18 class Requests_Auth_Basic implements Requests_Auth {
     23class Basic implements Auth {
    1924    /**
    2025     * Username
     
    3439     * Constructor
    3540     *
    36      * @throws Requests_Exception On incorrect number of arguments (`authbasicbadargs`)
     41     * @since 2.0 Throws an `InvalidArgument` exception.
     42     * @since 2.0 Throws an `ArgumentCount` exception instead of the Requests base `Exception.
     43     *
    3744     * @param array|null $args Array of user and password. Must have exactly two elements
     45     *
     46     * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not an array or null.
     47     * @throws \WpOrg\Requests\Exception\ArgumentCount   On incorrect number of array elements (`authbasicbadargs`).
    3848     */
    3949    public function __construct($args = null) {
    4050        if (is_array($args)) {
    4151            if (count($args) !== 2) {
    42                 throw new Requests_Exception('Invalid number of arguments', 'authbasicbadargs');
     52                throw ArgumentCount::create('an array with exactly two elements', count($args), 'authbasicbadargs');
    4353            }
    4454
    4555            list($this->user, $this->pass) = $args;
     56            return;
     57        }
     58
     59        if ($args !== null) {
     60            throw InvalidArgument::create(1, '$args', 'array|null', gettype($args));
    4661        }
    4762    }
     
    5065     * Register the necessary callbacks
    5166     *
    52      * @see curl_before_send
    53      * @see fsockopen_header
    54      * @param Requests_Hooks $hooks Hook system
     67     * @see \WpOrg\Requests\Auth\Basic::curl_before_send()
     68     * @see \WpOrg\Requests\Auth\Basic::fsockopen_header()
     69     * @param \WpOrg\Requests\Hooks $hooks Hook system
    5570     */
    56     public function register(Requests_Hooks $hooks) {
    57         $hooks->register('curl.before_send', array($this, 'curl_before_send'));
    58         $hooks->register('fsockopen.after_headers', array($this, 'fsockopen_header'));
     71    public function register(Hooks $hooks) {
     72        $hooks->register('curl.before_send', [$this, 'curl_before_send']);
     73        $hooks->register('fsockopen.after_headers', [$this, 'fsockopen_header']);
    5974    }
    6075
     
    6277     * Set cURL parameters before the data is sent
    6378     *
    64      * @param resource $handle cURL resource
     79     * @param resource|\CurlHandle $handle cURL handle
    6580     */
    6681    public function curl_before_send(&$handle) {
Note: See TracChangeset for help on using the changeset viewer.