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/Cookie/Jar.php

    r52244 r52328  
    33 * Cookie holder object
    44 *
    5  * @package Requests\Cookies
     5 * @package Requests
     6 * @subpackage Cookies
    67 */
    7 
    8 namespace WpOrg\Requests\Cookie;
    9 
    10 use ArrayAccess;
    11 use ArrayIterator;
    12 use IteratorAggregate;
    13 use ReturnTypeWillChange;
    14 use WpOrg\Requests\Cookie;
    15 use WpOrg\Requests\Exception;
    16 use WpOrg\Requests\Exception\InvalidArgument;
    17 use WpOrg\Requests\HookManager;
    18 use WpOrg\Requests\Iri;
    19 use WpOrg\Requests\Response;
    208
    219/**
    2210 * Cookie holder object
    2311 *
    24  * @package Requests\Cookies
     12 * @package Requests
     13 * @subpackage Cookies
    2514 */
    26 class Jar implements ArrayAccess, IteratorAggregate {
     15class Requests_Cookie_Jar implements ArrayAccess, IteratorAggregate {
    2716    /**
    2817     * Actual item data
     
    3019     * @var array
    3120     */
    32     protected $cookies = [];
     21    protected $cookies = array();
    3322
    3423    /**
     
    3625     *
    3726     * @param array $cookies Existing cookie values
    38      *
    39      * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not an array.
    4027     */
    41     public function __construct($cookies = []) {
    42         if (is_array($cookies) === false) {
    43             throw InvalidArgument::create(1, '$cookies', 'array', gettype($cookies));
    44         }
    45 
     28    public function __construct($cookies = array()) {
    4629        $this->cookies = $cookies;
    4730    }
    4831
    4932    /**
    50      * Normalise cookie data into a \WpOrg\Requests\Cookie
     33     * Normalise cookie data into a Requests_Cookie
    5134     *
    52      * @param string|\WpOrg\Requests\Cookie $cookie
    53      * @return \WpOrg\Requests\Cookie
     35     * @param string|Requests_Cookie $cookie
     36     * @return Requests_Cookie
    5437     */
    55     public function normalize_cookie($cookie, $key = '') {
    56         if ($cookie instanceof Cookie) {
     38    public function normalize_cookie($cookie, $key = null) {
     39        if ($cookie instanceof Requests_Cookie) {
    5740            return $cookie;
    5841        }
    5942
    60         return Cookie::parse($cookie, $key);
     43        return Requests_Cookie::parse($cookie, $key);
     44    }
     45
     46    /**
     47     * Normalise cookie data into a Requests_Cookie
     48     *
     49     * @codeCoverageIgnore
     50     * @deprecated Use {@see Requests_Cookie_Jar::normalize_cookie}
     51     * @return Requests_Cookie
     52     */
     53    public function normalizeCookie($cookie, $key = null) {
     54        return $this->normalize_cookie($cookie, $key);
    6155    }
    6256
     
    6458     * Check if the given item exists
    6559     *
    66      * @param string $offset Item key
     60     * @param string $key Item key
    6761     * @return boolean Does the item exist?
    6862     */
    69     #[ReturnTypeWillChange]
    70     public function offsetExists($offset) {
    71         return isset($this->cookies[$offset]);
     63    public function offsetExists($key) {
     64        return isset($this->cookies[$key]);
    7265    }
    7366
     
    7568     * Get the value for the item
    7669     *
    77      * @param string $offset Item key
     70     * @param string $key Item key
    7871     * @return string|null Item value (null if offsetExists is false)
    7972     */
    80     #[ReturnTypeWillChange]
    81     public function offsetGet($offset) {
    82         if (!isset($this->cookies[$offset])) {
     73    public function offsetGet($key) {
     74        if (!isset($this->cookies[$key])) {
    8375            return null;
    8476        }
    8577
    86         return $this->cookies[$offset];
     78        return $this->cookies[$key];
    8779    }
    8880
     
    9082     * Set the given item
    9183     *
    92      * @param string $offset Item name
     84     * @throws Requests_Exception On attempting to use dictionary as list (`invalidset`)
     85     *
     86     * @param string $key Item name
    9387     * @param string $value Item value
    94      *
    95      * @throws \WpOrg\Requests\Exception On attempting to use dictionary as list (`invalidset`)
    9688     */
    97     #[ReturnTypeWillChange]
    98     public function offsetSet($offset, $value) {
    99         if ($offset === null) {
    100             throw new Exception('Object is a dictionary, not a list', 'invalidset');
     89    public function offsetSet($key, $value) {
     90        if ($key === null) {
     91            throw new Requests_Exception('Object is a dictionary, not a list', 'invalidset');
    10192        }
    10293
    103         $this->cookies[$offset] = $value;
     94        $this->cookies[$key] = $value;
    10495    }
    10596
     
    10798     * Unset the given header
    10899     *
    109      * @param string $offset
     100     * @param string $key
    110101     */
    111     #[ReturnTypeWillChange]
    112     public function offsetUnset($offset) {
    113         unset($this->cookies[$offset]);
     102    public function offsetUnset($key) {
     103        unset($this->cookies[$key]);
    114104    }
    115105
     
    117107     * Get an iterator for the data
    118108     *
    119      * @return \ArrayIterator
     109     * @return ArrayIterator
    120110     */
    121     #[ReturnTypeWillChange]
    122111    public function getIterator() {
    123112        return new ArrayIterator($this->cookies);
     
    127116     * Register the cookie handler with the request's hooking system
    128117     *
    129      * @param \WpOrg\Requests\HookManager $hooks Hooking system
     118     * @param Requests_Hooker $hooks Hooking system
    130119     */
    131     public function register(HookManager $hooks) {
    132         $hooks->register('requests.before_request', [$this, 'before_request']);
    133         $hooks->register('requests.before_redirect_check', [$this, 'before_redirect_check']);
     120    public function register(Requests_Hooker $hooks) {
     121        $hooks->register('requests.before_request', array($this, 'before_request'));
     122        $hooks->register('requests.before_redirect_check', array($this, 'before_redirect_check'));
    134123    }
    135124
     
    146135     */
    147136    public function before_request($url, &$headers, &$data, &$type, &$options) {
    148         if (!$url instanceof Iri) {
    149             $url = new Iri($url);
     137        if (!$url instanceof Requests_IRI) {
     138            $url = new Requests_IRI($url);
    150139        }
    151140
    152141        if (!empty($this->cookies)) {
    153             $cookies = [];
     142            $cookies = array();
    154143            foreach ($this->cookies as $key => $cookie) {
    155144                $cookie = $this->normalize_cookie($cookie, $key);
     
    172161     * Parse all cookies from a response and attach them to the response
    173162     *
    174      * @param \WpOrg\Requests\Response $response
     163     * @var Requests_Response $response
    175164     */
    176     public function before_redirect_check(Response $response) {
    177         $url = $response->url;
    178         if (!$url instanceof Iri) {
    179             $url = new Iri($url);
     165    public function before_redirect_check(Requests_Response $return) {
     166        $url = $return->url;
     167        if (!$url instanceof Requests_IRI) {
     168            $url = new Requests_IRI($url);
    180169        }
    181170
    182         $cookies           = Cookie::parse_from_headers($response->headers, $url);
    183         $this->cookies     = array_merge($this->cookies, $cookies);
    184         $response->cookies = $this;
     171        $cookies         = Requests_Cookie::parse_from_headers($return->headers, $url);
     172        $this->cookies   = array_merge($this->cookies, $cookies);
     173        $return->cookies = $this;
    185174    }
    186175}
Note: See TracChangeset for help on using the changeset viewer.