Make WordPress Core


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

    r50842 r52244  
    33 * Case-insensitive dictionary, suitable for HTTP headers
    44 *
    5  * @package Requests
    6  * @subpackage Utilities
     5 * @package Requests\Utilities
    76 */
     7
     8namespace WpOrg\Requests\Utility;
     9
     10use ArrayAccess;
     11use ArrayIterator;
     12use IteratorAggregate;
     13use ReturnTypeWillChange;
     14use WpOrg\Requests\Exception;
    815
    916/**
    1017 * Case-insensitive dictionary, suitable for HTTP headers
    1118 *
    12  * @package Requests
    13  * @subpackage Utilities
     19 * @package Requests\Utilities
    1420 */
    15 class Requests_Utility_CaseInsensitiveDictionary implements ArrayAccess, IteratorAggregate {
     21class CaseInsensitiveDictionary implements ArrayAccess, IteratorAggregate {
    1622    /**
    1723     * Actual item data
     
    1925     * @var array
    2026     */
    21     protected $data = array();
     27    protected $data = [];
    2228
    2329    /**
     
    2632     * @param array $data Dictionary/map to convert to case-insensitive
    2733     */
    28     public function __construct(array $data = array()) {
    29         foreach ($data as $key => $value) {
    30             $this->offsetSet($key, $value);
     34    public function __construct(array $data = []) {
     35        foreach ($data as $offset => $value) {
     36            $this->offsetSet($offset, $value);
    3137        }
    3238    }
     
    3541     * Check if the given item exists
    3642     *
    37      * @param string $key Item key
     43     * @param string $offset Item key
    3844     * @return boolean Does the item exist?
    3945     */
    40     public function offsetExists($key) {
    41         $key = strtolower($key);
    42         return isset($this->data[$key]);
     46    #[ReturnTypeWillChange]
     47    public function offsetExists($offset) {
     48        if (is_string($offset)) {
     49            $offset = strtolower($offset);
     50        }
     51
     52        return isset($this->data[$offset]);
    4353    }
    4454
     
    4656     * Get the value for the item
    4757     *
    48      * @param string $key Item key
    49      * @return string|null Item value (null if offsetExists is false)
     58     * @param string $offset Item key
     59     * @return string|null Item value (null if the item key doesn't exist)
    5060     */
    51     public function offsetGet($key) {
    52         $key = strtolower($key);
    53         if (!isset($this->data[$key])) {
     61    #[ReturnTypeWillChange]
     62    public function offsetGet($offset) {
     63        if (is_string($offset)) {
     64            $offset = strtolower($offset);
     65        }
     66
     67        if (!isset($this->data[$offset])) {
    5468            return null;
    5569        }
    5670
    57         return $this->data[$key];
     71        return $this->data[$offset];
    5872    }
    5973
     
    6175     * Set the given item
    6276     *
    63      * @throws Requests_Exception On attempting to use dictionary as list (`invalidset`)
     77     * @param string $offset Item name
     78     * @param string $value Item value
    6479     *
    65      * @param string $key Item name
    66      * @param string $value Item value
     80     * @throws \WpOrg\Requests\Exception On attempting to use dictionary as list (`invalidset`)
    6781     */
    68     public function offsetSet($key, $value) {
    69         if ($key === null) {
    70             throw new Requests_Exception('Object is a dictionary, not a list', 'invalidset');
     82    #[ReturnTypeWillChange]
     83    public function offsetSet($offset, $value) {
     84        if ($offset === null) {
     85            throw new Exception('Object is a dictionary, not a list', 'invalidset');
    7186        }
    7287
    73         $key              = strtolower($key);
    74         $this->data[$key] = $value;
     88        if (is_string($offset)) {
     89            $offset = strtolower($offset);
     90        }
     91
     92        $this->data[$offset] = $value;
    7593    }
    7694
     
    7896     * Unset the given header
    7997     *
    80      * @param string $key
     98     * @param string $offset
    8199     */
    82     public function offsetUnset($key) {
    83         unset($this->data[strtolower($key)]);
     100    #[ReturnTypeWillChange]
     101    public function offsetUnset($offset) {
     102        if (is_string($offset)) {
     103            $offset = strtolower($offset);
     104        }
     105
     106        unset($this->data[$offset]);
    84107    }
    85108
     
    87110     * Get an iterator for the data
    88111     *
    89      * @return ArrayIterator
     112     * @return \ArrayIterator
    90113     */
     114    #[ReturnTypeWillChange]
    91115    public function getIterator() {
    92116        return new ArrayIterator($this->data);
Note: See TracChangeset for help on using the changeset viewer.