Make WordPress Core


Ignore:
Timestamp:
11/25/2021 01:10:30 AM (2 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/Utility/FilteredIterator.php

    r50842 r52244  
    33 * Iterator for arrays requiring filtered values
    44 *
    5  * @package Requests
    6  * @subpackage Utilities
     5 * @package Requests\Utilities
    76 */
     7
     8namespace WpOrg\Requests\Utility;
     9
     10use ArrayIterator;
     11use ReturnTypeWillChange;
     12use WpOrg\Requests\Exception\InvalidArgument;
     13use WpOrg\Requests\Utility\InputValidator;
    814
    915/**
    1016 * Iterator for arrays requiring filtered values
    1117 *
    12  * @package Requests
    13  * @subpackage Utilities
     18 * @package Requests\Utilities
    1419 */
    15 class Requests_Utility_FilteredIterator extends ArrayIterator {
     20final class FilteredIterator extends ArrayIterator {
    1621    /**
    1722     * Callback to run as a filter
     
    1924     * @var callable
    2025     */
    21     protected $callback;
     26    private $callback;
    2227
    2328    /**
     
    2631     * @param array $data
    2732     * @param callable $callback Callback to be called on each value
     33     *
     34     * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $data argument is not iterable.
    2835     */
    2936    public function __construct($data, $callback) {
     37        if (InputValidator::is_iterable($data) === false) {
     38            throw InvalidArgument::create(1, '$data', 'iterable', gettype($data));
     39        }
     40
    3041        parent::__construct($data);
    3142
    32         $this->callback = $callback;
     43        if (is_callable($callback)) {
     44            $this->callback = $callback;
     45        }
     46    }
     47
     48    /**
     49     * @inheritdoc
     50     *
     51     * @phpcs:disable PHPCompatibility.FunctionNameRestrictions.NewMagicMethods.__unserializeFound
     52     */
     53    #[ReturnTypeWillChange]
     54    public function __unserialize($data) {}
     55    // phpcs:enable
     56
     57    public function __wakeup() {
     58        unset($this->callback);
    3359    }
    3460
     
    3864     * @return string
    3965     */
     66    #[ReturnTypeWillChange]
    4067    public function current() {
    4168        $value = parent::current();
     
    5178     * @inheritdoc
    5279     */
    53     public function unserialize($serialized) {}
    54 
    55     /**
    56      * @inheritdoc
    57      *
    58      * @phpcs:disable PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.MethodDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.NewMagicMethods.__unserializeFound
    59      */
    60     public function __unserialize($serialized) {}
    61 
    62     public function __wakeup() {
    63         unset($this->callback);
    64     }
     80    #[ReturnTypeWillChange]
     81    public function unserialize($data) {}
    6582}
Note: See TracChangeset for help on using the changeset viewer.