Make WordPress Core


Ignore:
Timestamp:
12/06/2021 09:29:00 PM (2 years ago)
Author:
SergeyBiryukov
Message:

HTTP API: Revert changeset [52244].

Reverting Requests 2.0.0 changes and moving to WordPress 6.0 cycle. Why? The namespace and file case renaming revealed 2 issues in Core's upgrader process.

See https://core.trac.wordpress.org/ticket/54504#comment:22 for more information.

Follow-up to [52327].

See #54562, #54504.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/Requests/Response/Headers.php

    r52244 r52328  
    66 */
    77
    8 namespace WpOrg\Requests\Response;
    9 
    10 use WpOrg\Requests\Exception;
    11 use WpOrg\Requests\Exception\InvalidArgument;
    12 use WpOrg\Requests\Utility\CaseInsensitiveDictionary;
    13 use WpOrg\Requests\Utility\FilteredIterator;
    14 
    158/**
    169 * Case-insensitive dictionary, suitable for HTTP headers
     
    1811 * @package Requests
    1912 */
    20 class Headers extends CaseInsensitiveDictionary {
     13class Requests_Response_Headers extends Requests_Utility_CaseInsensitiveDictionary {
    2114    /**
    2215     * Get the given header
    2316     *
    24      * Unlike {@see \WpOrg\Requests\Response\Headers::getValues()}, this returns a string. If there are
     17     * Unlike {@see self::getValues()}, this returns a string. If there are
    2518     * multiple values, it concatenates them with a comma as per RFC2616.
    2619     *
     
    2821     * Set-Cookie headers.
    2922     *
    30      * @param string $offset
     23     * @param string $key
    3124     * @return string|null Header value
    3225     */
    33     public function offsetGet($offset) {
    34         if (is_string($offset)) {
    35             $offset = strtolower($offset);
    36         }
    37 
    38         if (!isset($this->data[$offset])) {
     26    public function offsetGet($key) {
     27        $key = strtolower($key);
     28        if (!isset($this->data[$key])) {
    3929            return null;
    4030        }
    4131
    42         return $this->flatten($this->data[$offset]);
     32        return $this->flatten($this->data[$key]);
    4333    }
    4434
     
    4636     * Set the given item
    4737     *
    48      * @param string $offset Item name
     38     * @throws Requests_Exception On attempting to use dictionary as list (`invalidset`)
     39     *
     40     * @param string $key Item name
    4941     * @param string $value Item value
    50      *
    51      * @throws \WpOrg\Requests\Exception On attempting to use dictionary as list (`invalidset`)
    5242     */
    53     public function offsetSet($offset, $value) {
    54         if ($offset === null) {
    55             throw new Exception('Object is a dictionary, not a list', 'invalidset');
     43    public function offsetSet($key, $value) {
     44        if ($key === null) {
     45            throw new Requests_Exception('Object is a dictionary, not a list', 'invalidset');
    5646        }
    5747
    58         if (is_string($offset)) {
    59             $offset = strtolower($offset);
     48        $key = strtolower($key);
     49
     50        if (!isset($this->data[$key])) {
     51            $this->data[$key] = array();
    6052        }
    6153
    62         if (!isset($this->data[$offset])) {
    63             $this->data[$offset] = [];
    64         }
    65 
    66         $this->data[$offset][] = $value;
     54        $this->data[$key][] = $value;
    6755    }
    6856
     
    7058     * Get all values for a given header
    7159     *
    72      * @param string $offset
     60     * @param string $key
    7361     * @return array|null Header values
    74      *
    75      * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not valid as an array key.
    7662     */
    77     public function getValues($offset) {
    78         if (!is_string($offset) && !is_int($offset)) {
    79             throw InvalidArgument::create(1, '$offset', 'string|int', gettype($offset));
    80         }
    81 
    82         $offset = strtolower($offset);
    83         if (!isset($this->data[$offset])) {
     63    public function getValues($key) {
     64        $key = strtolower($key);
     65        if (!isset($this->data[$key])) {
    8466            return null;
    8567        }
    8668
    87         return $this->data[$offset];
     69        return $this->data[$key];
    8870    }
    8971
     
    9678     * @param string|array $value Value to flatten
    9779     * @return string Flattened value
    98      *
    99      * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not a string or an array.
    10080     */
    10181    public function flatten($value) {
    102         if (is_string($value)) {
    103             return $value;
     82        if (is_array($value)) {
     83            $value = implode(',', $value);
    10484        }
    10585
    106         if (is_array($value)) {
    107             return implode(',', $value);
    108         }
    109 
    110         throw InvalidArgument::create(1, '$value', 'string|array', gettype($value));
     86        return $value;
    11187    }
    11288
     
    11490     * Get an iterator for the data
    11591     *
    116      * Converts the internally stored values to a comma-separated string if there is more
    117      * than one value for a key.
    118      *
    119      * @return \ArrayIterator
     92     * Converts the internal
     93     * @return ArrayIterator
    12094     */
    12195    public function getIterator() {
    122         return new FilteredIterator($this->data, [$this, 'flatten']);
     96        return new Requests_Utility_FilteredIterator($this->data, array($this, 'flatten'));
    12397    }
    12498}
Note: See TracChangeset for help on using the changeset viewer.