Make WordPress Core

Ticket #47991: 47991.patch

File 47991.patch, 12.2 KB (added by dkarfa, 7 years ago)
  • wp-includes/Requests/Session.php

     
    2222         * Base URL for requests
    2323         *
    2424         * URLs will be made absolute using this as the base
     25         *
    2526         * @var string|null
    2627         */
    2728        public $url = null;
    … …  
    2829
    2930        /**
    3031         * Base headers for requests
     32         *
    3133         * @var array
    3234         */
    3335        public $headers = array();
    … …  
    5860        /**
    5961         * Create a new session
    6062         *
    61          * @param string|null $url Base URL for requests
    62          * @param array $headers Default headers for requests
    63          * @param array $data Default data for requests
    64          * @param array $options Default options for requests
     63         * @param string|null $url Base URL for requests.
     64         * @param array       $headers Default headers for requests.
     65         * @param array       $data Default data for requests.
     66         * @param array       $options Default options for requests.
    6567         */
    66         public function __construct($url = null, $headers = array(), $data = array(), $options = array()) {
    67                 $this->url = $url;
     68        public function __construct( $url = null, $headers = array(), $data = array(), $options = array() ) {
     69                $this->url     = $url;
    6870                $this->headers = $headers;
    69                 $this->data = $data;
     71                $this->data    = $data;
    7072                $this->options = $options;
    7173
    72                 if (empty($this->options['cookies'])) {
     74                if ( empty( $this->options['cookies'] ) ) {
    7375                        $this->options['cookies'] = new Requests_Cookie_Jar();
    7476                }
    7577        }
    … …  
    7779        /**
    7880         * Get a property's value
    7981         *
    80          * @param string $key Property key
     82         * @param string $key Property key.
    8183         * @return mixed|null Property value, null if none found
    8284         */
    83         public function __get($key) {
    84                 if (isset($this->options[$key])) {
    85                         return $this->options[$key];
     85        public function __get( $key ) {
     86                if ( isset( $this->options[ $key ] ) ) {
     87                        return $this->options[ $key ];
    8688                }
    8789
    8890                return null;
    … …  
    9193        /**
    9294         * Set a property's value
    9395         *
    94          * @param string $key Property key
    95          * @param mixed $value Property value
     96         * @param string $key Property key.
     97         * @param mixed  $value Property value.
    9698         */
    97         public function __set($key, $value) {
    98                 $this->options[$key] = $value;
     99        public function __set( $key, $value ) {
     100                $this->options[ $key ] = $value;
    99101        }
    100102
    101103        /**
    102104         * Remove a property's value
    103105         *
    104          * @param string $key Property key
     106         * @param string $key Property key.
    105107         */
    106         public function __isset($key) {
    107                 return isset($this->options[$key]);
     108        public function __isset( $key ) {
     109                return isset( $this->options[ $key ] );
    108110        }
    109111
    110112        /**
    111113         * Remove a property's value
    112114         *
    113          * @param string $key Property key
     115         * @param string $key Property key.
    114116         */
    115         public function __unset($key) {
    116                 if (isset($this->options[$key])) {
    117                         unset($this->options[$key]);
     117        public function __unset( $key ) {
     118                if ( isset( $this->options[ $key ] ) ) {
     119                        unset( $this->options[ $key ] );
    118120                }
    119121        }
    120122
    121         /**#@+
     123        /**
     124         * Send a GET request
     125         *
    122126         * @see request()
    123          * @param string $url
    124          * @param array $headers
    125          * @param array $options
     127         * @param  string $url     URL to request.
     128         * @param  array  $headers Extra headers to send with the request.
     129         * @param  array  $options Options for the request (see {@see Requests::request}).
    126130         * @return Requests_Response
    127131         */
    128         /**
    129          * Send a GET request
    130          */
    131         public function get($url, $headers = array(), $options = array()) {
    132                 return $this->request($url, $headers, null, Requests::GET, $options);
     132        public function get( $url, $headers = array(), $options = array() ) {
     133                return $this->request( $url, $headers, null, Requests::GET, $options );
    133134        }
    134135
    135136        /**
    136137         * Send a HEAD request
     138         *
     139         * @param  string $url     URL to request.
     140         * @param  array  $headers Extra headers to send with the request.
     141         * @param  array  $options Options for the request (see {@see Requests::request}).
     142         * @return Requests_Response
    137143         */
    138         public function head($url, $headers = array(), $options = array()) {
    139                 return $this->request($url, $headers, null, Requests::HEAD, $options);
     144        public function head( $url, $headers = array(), $options = array() ) {
     145                return $this->request( $url, $headers, null, Requests::HEAD, $options );
    140146        }
    141147
    142148        /**
    143149         * Send a DELETE request
     150         *
     151         * @param  string $url     URL to request.
     152         * @param  array  $headers Extra headers to send with the request.
     153         * @param  array  $options Options for the request (see {@see Requests::request}).
     154         * @return Requests_Response
    144155         */
    145         public function delete($url, $headers = array(), $options = array()) {
    146                 return $this->request($url, $headers, null, Requests::DELETE, $options);
     156        public function delete( $url, $headers = array(), $options = array() ) {
     157                return $this->request( $url, $headers, null, Requests::DELETE, $options );
    147158        }
    148         /**#@-*/
    149159
    150         /**#@+
     160        /**
     161         * Send a POST request
     162         *
    151163         * @see request()
    152          * @param string $url
    153          * @param array $headers
    154          * @param array $data
    155          * @param array $options
     164         * @param string     $url     URL to request.
     165         * @param array      $headers Extra headers to send with the request.
     166         * @param array|null $data    Data to send either as a query string for GET/HEAD requests, or in the body for POST requests.
     167         * @param array      $options Options for the request (see {@see Requests::request}).
    156168         * @return Requests_Response
    157169         */
    158         /**
    159          * Send a POST request
    160          */
    161         public function post($url, $headers = array(), $data = array(), $options = array()) {
    162                 return $this->request($url, $headers, $data, Requests::POST, $options);
     170        public function post( $url, $headers = array(), $data = array(), $options = array() ) {
     171                return $this->request( $url, $headers, $data, Requests::POST, $options );
    163172        }
    164173
    165174        /**
    166175         * Send a PUT request
     176         *
     177         * @param  string     $url     URL to request.
     178         * @param  array      $headers Extra headers to send with the request.
     179         * @param  array|null $data    Data to send either as a query string for GET/HEAD requests, or in the body for POST requests.
     180         * @param  array      $options Options for the request (see {@see Requests::request}).
     181         * @return Requests_Response
    167182         */
    168         public function put($url, $headers = array(), $data = array(), $options = array()) {
    169                 return $this->request($url, $headers, $data, Requests::PUT, $options);
     183        public function put( $url, $headers = array(), $data = array(), $options = array() ) {
     184                return $this->request( $url, $headers, $data, Requests::PUT, $options );
    170185        }
    171186
    172187        /**
    … …  
    176191         * specification recommends that should send an ETag
    177192         *
    178193         * @link https://tools.ietf.org/html/rfc5789
     194         *
     195         * @param  string     $url     URL to request.
     196         * @param  array      $headers Extra headers to send with the request.
     197         * @param  array|null $data    Data to send either as a query string for GET/HEAD requests, or in the body for POST requests.
     198         * @param  array      $options Options for the request (see {@see Requests::request}).
     199         * @return Requests_Response
    179200         */
    180         public function patch($url, $headers, $data = array(), $options = array()) {
    181                 return $this->request($url, $headers, $data, Requests::PATCH, $options);
     201        public function patch( $url, $headers, $data = array(), $options = array() ) {
     202                return $this->request( $url, $headers, $data, Requests::PATCH, $options );
    182203        }
    183         /**#@-*/
    184204
    185205        /**
    186206         * Main interface for HTTP requests
    … …  
    190210         *
    191211         * @see Requests::request()
    192212         *
    193          * @throws Requests_Exception On invalid URLs (`nonhttp`)
     213         * @throws Requests_Exception On invalid URLs (`nonhttp`).
    194214         *
    195          * @param string $url URL to request
    196          * @param array $headers Extra headers to send with the request
    197          * @param array|null $data Data to send either as a query string for GET/HEAD requests, or in the body for POST requests
    198          * @param string $type HTTP request type (use Requests constants)
    199          * @param array $options Options for the request (see {@see Requests::request})
     215         * @param string     $url     URL to request.
     216         * @param array      $headers Extra headers to send with the request.
     217         * @param array|null $data    Data to send either as a query string for GET/HEAD requests, or in the body for POST requests.
     218         * @param string     $type    HTTP request type (use Requests constants).
     219         * @param array      $options Options for the request (see {@see Requests::request}).
    200220         * @return Requests_Response
    201221         */
    202         public function request($url, $headers = array(), $data = array(), $type = Requests::GET, $options = array()) {
    203                 $request = $this->merge_request(compact('url', 'headers', 'data', 'options'));
     222        public function request( $url, $headers = array(), $data = array(), $type = Requests::GET, $options = array() ) {
     223                $request = $this->merge_request( compact( 'url', 'headers', 'data', 'options' ) );
    204224
    205                 return Requests::request($request['url'], $request['headers'], $request['data'], $type, $request['options']);
     225                return Requests::request( $request['url'], $request['headers'], $request['data'], $type, $request['options'] );
    206226        }
    207227
    208228        /**
    … …  
    210230         *
    211231         * @see Requests::request_multiple()
    212232         *
    213          * @param array $requests Requests data (see {@see Requests::request_multiple})
    214          * @param array $options Global and default options (see {@see Requests::request})
    215          * @return array Responses (either Requests_Response or a Requests_Exception object)
     233         * @param array $requests  Requests data (see {@see Requests::request_multiple}).
     234         * @param array $options   Global and default options (see {@see Requests::request}).
     235         * @return array Responses (either Requests_Response or a Requests_Exception object).
    216236         */
    217         public function request_multiple($requests, $options = array()) {
    218                 foreach ($requests as $key => $request) {
    219                         $requests[$key] = $this->merge_request($request, false);
     237        public function request_multiple( $requests, $options = array() ) {
     238                foreach ( $requests as $key => $request ) {
     239                        $requests[ $key ] = $this->merge_request( $request, false );
    220240                }
    221241
    222                 $options = array_merge($this->options, $options);
     242                $options = array_merge( $this->options, $options );
    223243
    224                 // Disallow forcing the type, as that's a per request setting
    225                 unset($options['type']);
     244                // Disallow forcing the type, as that's a per request setting.
     245                unset( $options['type'] );
    226246
    227                 return Requests::request_multiple($requests, $options);
     247                return Requests::request_multiple( $requests, $options );
    228248        }
    229249
    230250        /**
    231251         * Merge a request's data with the default data
    232252         *
    233          * @param array $request Request data (same form as {@see request_multiple})
    234          * @param boolean $merge_options Should we merge options as well?
    235          * @return array Request data
     253         * @param array   $request Request data (same form as {@see request_multiple}).
     254         * @param boolean $merge_options Should we merge options as well?.
     255         * @return array  Request data
    236256         */
    237         protected function merge_request($request, $merge_options = true) {
    238                 if ($this->url !== null) {
    239                         $request['url'] = Requests_IRI::absolutize($this->url, $request['url']);
     257        protected function merge_request( $request, $merge_options = true ) {
     258                if ( null !== $this->url ) {
     259                        $request['url'] = Requests_IRI::absolutize( $this->url, $request['url'] );
    240260                        $request['url'] = $request['url']->uri;
    241261                }
    242262
    243                 if (empty($request['headers'])) {
     263                if ( empty( $request['headers'] ) ) {
    244264                        $request['headers'] = array();
    245265                }
    246                 $request['headers'] = array_merge($this->headers, $request['headers']);
     266                $request['headers'] = array_merge( $this->headers, $request['headers'] );
    247267
    248                 if (empty($request['data'])) {
    249                         if (is_array($this->data)) {
     268                if ( empty( $request['data'] ) ) {
     269                        if ( is_array( $this->data ) ) {
    250270                                $request['data'] = $this->data;
    251271                        }
     272                } elseif ( is_array( $request['data'] ) && is_array( $this->data ) ) {
     273                        $request['data'] = array_merge( $this->data, $request['data'] );
    252274                }
    253                 elseif (is_array($request['data']) && is_array($this->data)) {
    254                         $request['data'] = array_merge($this->data, $request['data']);
    255                 }
    256275
    257                 if ($merge_options !== false) {
    258                         $request['options'] = array_merge($this->options, $request['options']);
     276                if ( false !== $merge_options ) {
     277                        $request['options'] = array_merge( $this->options, $request['options'] );
    259278
    260                         // Disallow forcing the type, as that's a per request setting
    261                         unset($request['options']['type']);
     279                        // Disallow forcing the type, as that's a per request setting.
     280                        unset( $request['options']['type'] );
    262281                }
    263282
    264283                return $request;