Changeset 52328
- Timestamp:
- 12/06/2021 09:29:00 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 18 deleted
- 26 edited
- 11 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/Requests/Auth.php
r52244 r52328 3 3 * Authentication provider interface 4 4 * 5 * @package Requests\Authentication 5 * @package Requests 6 * @subpackage Authentication 6 7 */ 7 8 namespace WpOrg\Requests;9 10 use WpOrg\Requests\Hooks;11 8 12 9 /** … … 18 15 * makes it much easier for users to use your provider. 19 16 * 20 * @see \WpOrg\Requests\Hooks21 * 22 * @ package Requests\Authentication17 * @see Requests_Hooks 18 * @package Requests 19 * @subpackage Authentication 23 20 */ 24 interface Auth {21 interface Requests_Auth { 25 22 /** 26 23 * Register hooks as needed 27 24 * 28 * This method is called in {@see \WpOrg\Requests\Requests::request()} when the user29 * has setan instance as the 'auth' option. Use this callback to register all the25 * This method is called in {@see Requests::request} when the user has set 26 * an instance as the 'auth' option. Use this callback to register all the 30 27 * hooks you'll need. 31 28 * 32 * @see \WpOrg\Requests\Hooks::register()33 * @param \WpOrg\Requests\Hooks $hooks Hook system29 * @see Requests_Hooks::register 30 * @param Requests_Hooks $hooks Hook system 34 31 */ 35 public function register( Hooks $hooks);32 public function register(Requests_Hooks $hooks); 36 33 } -
trunk/src/wp-includes/Requests/Auth/Basic.php
r52244 r52328 3 3 * Basic Authentication provider 4 4 * 5 * @package Requests\Authentication 5 * @package Requests 6 * @subpackage Authentication 6 7 */ 7 8 namespace WpOrg\Requests\Auth;9 10 use WpOrg\Requests\Auth;11 use WpOrg\Requests\Exception\ArgumentCount;12 use WpOrg\Requests\Exception\InvalidArgument;13 use WpOrg\Requests\Hooks;14 8 15 9 /** … … 19 13 * header. 20 14 * 21 * @package Requests\Authentication 15 * @package Requests 16 * @subpackage Authentication 22 17 */ 23 class Basic implementsAuth {18 class Requests_Auth_Basic implements Requests_Auth { 24 19 /** 25 20 * Username … … 39 34 * Constructor 40 35 * 41 * @since 2.0 Throws an `InvalidArgument` exception. 42 * @since 2.0 Throws an `ArgumentCount` exception instead of the Requests base `Exception. 43 * 36 * @throws Requests_Exception On incorrect number of arguments (`authbasicbadargs`) 44 37 * @param array|null $args Array of user and password. Must have exactly two elements 45 *46 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not an array or null.47 * @throws \WpOrg\Requests\Exception\ArgumentCount On incorrect number of array elements (`authbasicbadargs`).48 38 */ 49 39 public function __construct($args = null) { 50 40 if (is_array($args)) { 51 41 if (count($args) !== 2) { 52 throw ArgumentCount::create('an array with exactly two elements', count($args), 'authbasicbadargs');42 throw new Requests_Exception('Invalid number of arguments', 'authbasicbadargs'); 53 43 } 54 44 55 45 list($this->user, $this->pass) = $args; 56 return;57 }58 59 if ($args !== null) {60 throw InvalidArgument::create(1, '$args', 'array|null', gettype($args));61 46 } 62 47 } … … 65 50 * Register the necessary callbacks 66 51 * 67 * @see \WpOrg\Requests\Auth\Basic::curl_before_send()68 * @see \WpOrg\Requests\Auth\Basic::fsockopen_header()69 * @param \WpOrg\Requests\Hooks $hooks Hook system52 * @see curl_before_send 53 * @see fsockopen_header 54 * @param Requests_Hooks $hooks Hook system 70 55 */ 71 public function register( Hooks $hooks) {72 $hooks->register('curl.before_send', [$this, 'curl_before_send']);73 $hooks->register('fsockopen.after_headers', [$this, 'fsockopen_header']);56 public function register(Requests_Hooks $hooks) { 57 $hooks->register('curl.before_send', array($this, 'curl_before_send')); 58 $hooks->register('fsockopen.after_headers', array($this, 'fsockopen_header')); 74 59 } 75 60 … … 77 62 * Set cURL parameters before the data is sent 78 63 * 79 * @param resource |\CurlHandle $handle cURL handle64 * @param resource $handle cURL resource 80 65 */ 81 66 public function curl_before_send(&$handle) { -
trunk/src/wp-includes/Requests/Cookie.php
r52244 r52328 3 3 * Cookie storage object 4 4 * 5 * @package Requests\Cookies 5 * @package Requests 6 * @subpackage Cookies 6 7 */ 7 8 namespace WpOrg\Requests;9 10 use WpOrg\Requests\Exception\InvalidArgument;11 use WpOrg\Requests\Iri;12 use WpOrg\Requests\Response\Headers;13 use WpOrg\Requests\Utility\CaseInsensitiveDictionary;14 use WpOrg\Requests\Utility\InputValidator;15 8 16 9 /** 17 10 * Cookie storage object 18 11 * 19 * @package Requests\Cookies 12 * @package Requests 13 * @subpackage Cookies 20 14 */ 21 class Cookie {15 class Requests_Cookie { 22 16 /** 23 17 * Cookie name. … … 40 34 * httponly. 41 35 * 42 * @var \WpOrg\Requests\Utility\CaseInsensitiveDictionary|array Array-like object43 */ 44 public $attributes = [];36 * @var Requests_Utility_CaseInsensitiveDictionary|array Array-like object 37 */ 38 public $attributes = array(); 45 39 46 40 /** … … 52 46 * @var array 53 47 */ 54 public $flags = [];48 public $flags = array(); 55 49 56 50 /** … … 69 63 * @param string $name 70 64 * @param string $value 71 * @param array|\WpOrg\Requests\Utility\CaseInsensitiveDictionary $attributes Associative array of attribute data 72 * @param array $flags 73 * @param int|null $reference_time 74 * 75 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $name argument is not a string. 76 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $value argument is not a string. 77 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $attributes argument is not an array or iterable object with array access. 78 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $flags argument is not an array. 79 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $reference_time argument is not an integer or null. 80 */ 81 public function __construct($name, $value, $attributes = [], $flags = [], $reference_time = null) { 82 if (is_string($name) === false) { 83 throw InvalidArgument::create(1, '$name', 'string', gettype($name)); 84 } 85 86 if (is_string($value) === false) { 87 throw InvalidArgument::create(2, '$value', 'string', gettype($value)); 88 } 89 90 if (InputValidator::has_array_access($attributes) === false || InputValidator::is_iterable($attributes) === false) { 91 throw InvalidArgument::create(3, '$attributes', 'array|ArrayAccess&Traversable', gettype($attributes)); 92 } 93 94 if (is_array($flags) === false) { 95 throw InvalidArgument::create(4, '$flags', 'array', gettype($flags)); 96 } 97 98 if ($reference_time !== null && is_int($reference_time) === false) { 99 throw InvalidArgument::create(5, '$reference_time', 'integer|null', gettype($reference_time)); 100 } 101 65 * @param array|Requests_Utility_CaseInsensitiveDictionary $attributes Associative array of attribute data 66 */ 67 public function __construct($name, $value, $attributes = array(), $flags = array(), $reference_time = null) { 102 68 $this->name = $name; 103 69 $this->value = $value; 104 70 $this->attributes = $attributes; 105 $default_flags = [71 $default_flags = array( 106 72 'creation' => time(), 107 73 'last-access' => time(), 108 74 'persistent' => false, 109 75 'host-only' => true, 110 ];76 ); 111 77 $this->flags = array_merge($default_flags, $flags); 112 78 … … 117 83 118 84 $this->normalize(); 119 }120 121 /**122 * Get the cookie value123 *124 * Attributes and other data can be accessed via methods.125 */126 public function __toString() {127 return $this->value;128 85 } 129 86 … … 157 114 * Check if a cookie is valid for a given URI 158 115 * 159 * @param \WpOrg\Requests\Iri$uri URI to check116 * @param Requests_IRI $uri URI to check 160 117 * @return boolean Whether the cookie is valid for the given URI 161 118 */ 162 public function uri_matches( Iri$uri) {119 public function uri_matches(Requests_IRI $uri) { 163 120 if (!$this->domain_matches($uri->host)) { 164 121 return false; … … 175 132 * Check if a cookie is valid for a given domain 176 133 * 177 * @param string $ domainDomain to check134 * @param string $string Domain to check 178 135 * @return boolean Whether the cookie is valid for the given domain 179 136 */ 180 public function domain_matches($domain) { 181 if (is_string($domain) === false) { 182 return false; 183 } 184 137 public function domain_matches($string) { 185 138 if (!isset($this->attributes['domain'])) { 186 139 // Cookies created manually; cookies created by Requests will set … … 189 142 } 190 143 191 $ cookie_domain= $this->attributes['domain'];192 if ($ cookie_domain === $domain) {193 // The cookie domain and the passed domainare identical.144 $domain_string = $this->attributes['domain']; 145 if ($domain_string === $string) { 146 // The domain string and the string are identical. 194 147 return true; 195 148 } … … 201 154 } 202 155 203 if (strlen($ domain) <= strlen($cookie_domain)) {204 // For obvious reasons, the cookie domain cannot be a suffix if the passeddomain205 // is shorter than the cookie domain156 if (strlen($string) <= strlen($domain_string)) { 157 // For obvious reasons, the string cannot be a suffix if the domain 158 // is shorter than the domain string 206 159 return false; 207 160 } 208 161 209 if (substr($ domain, -1 * strlen($cookie_domain)) !== $cookie_domain) {210 // The cookie domain should be a suffix of the passed domain.162 if (substr($string, -1 * strlen($domain_string)) !== $domain_string) { 163 // The domain string should be a suffix of the string. 211 164 return false; 212 165 } 213 166 214 $prefix = substr($ domain, 0, strlen($domain) - strlen($cookie_domain));167 $prefix = substr($string, 0, strlen($string) - strlen($domain_string)); 215 168 if (substr($prefix, -1) !== '.') { 216 // The last character of the passed domainthat is not included in the169 // The last character of the string that is not included in the 217 170 // domain string should be a %x2E (".") character. 218 171 return false; 219 172 } 220 173 221 // The passed domainshould be a host name (i.e., not an IP address).222 return !preg_match('#^(.+\.)\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $ domain);174 // The string should be a host name (i.e., not an IP address). 175 return !preg_match('#^(.+\.)\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $string); 223 176 } 224 177 … … 241 194 // the path to the requested path 242 195 return true; 243 }244 245 if (is_scalar($request_path) === false) {246 return false;247 196 } 248 197 … … 369 318 370 319 /** 320 * Format a cookie for a Cookie header 321 * 322 * @codeCoverageIgnore 323 * @deprecated Use {@see Requests_Cookie::format_for_header} 324 * @return string 325 */ 326 public function formatForHeader() { 327 return $this->format_for_header(); 328 } 329 330 /** 371 331 * Format a cookie for a Set-Cookie header 372 332 * … … 379 339 $header_value = $this->format_for_header(); 380 340 if (!empty($this->attributes)) { 381 $parts = [];341 $parts = array(); 382 342 foreach ($this->attributes as $key => $value) { 383 343 // Ignore non-associative attributes … … 396 356 397 357 /** 358 * Format a cookie for a Set-Cookie header 359 * 360 * @codeCoverageIgnore 361 * @deprecated Use {@see Requests_Cookie::format_for_set_cookie} 362 * @return string 363 */ 364 public function formatForSetCookie() { 365 return $this->format_for_set_cookie(); 366 } 367 368 /** 369 * Get the cookie value 370 * 371 * Attributes and other data can be accessed via methods. 372 */ 373 public function __toString() { 374 return $this->value; 375 } 376 377 /** 398 378 * Parse a cookie string into a cookie object 399 379 * … … 402 382 * specifies some of this handling, but not in a thorough manner. 403 383 * 404 * @param string $cookie_header Cookie header value (from a Set-Cookie header) 405 * @param string $name 406 * @param int|null $reference_time 407 * @return \WpOrg\Requests\Cookie Parsed cookie object 408 * 409 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $cookie_header argument is not a string. 410 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $name argument is not a string. 411 */ 412 public static function parse($cookie_header, $name = '', $reference_time = null) { 413 if (is_string($cookie_header) === false) { 414 throw InvalidArgument::create(1, '$cookie_header', 'string', gettype($cookie_header)); 415 } 416 417 if (is_string($name) === false) { 418 throw InvalidArgument::create(2, '$name', 'string', gettype($name)); 419 } 420 421 $parts = explode(';', $cookie_header); 384 * @param string Cookie header value (from a Set-Cookie header) 385 * @return Requests_Cookie Parsed cookie object 386 */ 387 public static function parse($string, $name = '', $reference_time = null) { 388 $parts = explode(';', $string); 422 389 $kvparts = array_shift($parts); 423 390 424 391 if (!empty($name)) { 425 $value = $ cookie_header;392 $value = $string; 426 393 } 427 394 elseif (strpos($kvparts, '=') === false) { … … 440 407 $value = trim($value); 441 408 442 // Attribute key sare handled case-insensitively443 $attributes = new CaseInsensitiveDictionary();409 // Attribute key are handled case-insensitively 410 $attributes = new Requests_Utility_CaseInsensitiveDictionary(); 444 411 445 412 if (!empty($parts)) { … … 459 426 } 460 427 461 return new static($name, $value, $attributes, [], $reference_time);428 return new Requests_Cookie($name, $value, $attributes, array(), $reference_time); 462 429 } 463 430 … … 465 432 * Parse all Set-Cookie headers from request headers 466 433 * 467 * @param \WpOrg\Requests\Response\Headers $headers Headers to parse from468 * @param \WpOrg\Requests\Iri|null $origin URI for comparing cookie origins434 * @param Requests_Response_Headers $headers Headers to parse from 435 * @param Requests_IRI|null $origin URI for comparing cookie origins 469 436 * @param int|null $time Reference time for expiration calculation 470 437 * @return array 471 438 */ 472 public static function parse_from_headers( Headers $headers, Iri$origin = null, $time = null) {439 public static function parse_from_headers(Requests_Response_Headers $headers, Requests_IRI $origin = null, $time = null) { 473 440 $cookie_headers = $headers->getValues('Set-Cookie'); 474 441 if (empty($cookie_headers)) { 475 return [];476 } 477 478 $cookies = [];442 return array(); 443 } 444 445 $cookies = array(); 479 446 foreach ($cookie_headers as $header) { 480 447 $parsed = self::parse($header, '', $time); … … 525 492 return $cookies; 526 493 } 494 495 /** 496 * Parse all Set-Cookie headers from request headers 497 * 498 * @codeCoverageIgnore 499 * @deprecated Use {@see Requests_Cookie::parse_from_headers} 500 * @return array 501 */ 502 public static function parseFromHeaders(Requests_Response_Headers $headers) { 503 return self::parse_from_headers($headers); 504 } 527 505 } -
trunk/src/wp-includes/Requests/Cookie/Jar.php
r52244 r52328 3 3 * Cookie holder object 4 4 * 5 * @package Requests\Cookies 5 * @package Requests 6 * @subpackage Cookies 6 7 */ 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;20 8 21 9 /** 22 10 * Cookie holder object 23 11 * 24 * @package Requests\Cookies 12 * @package Requests 13 * @subpackage Cookies 25 14 */ 26 class Jar implements ArrayAccess, IteratorAggregate {15 class Requests_Cookie_Jar implements ArrayAccess, IteratorAggregate { 27 16 /** 28 17 * Actual item data … … 30 19 * @var array 31 20 */ 32 protected $cookies = [];21 protected $cookies = array(); 33 22 34 23 /** … … 36 25 * 37 26 * @param array $cookies Existing cookie values 38 *39 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not an array.40 27 */ 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()) { 46 29 $this->cookies = $cookies; 47 30 } 48 31 49 32 /** 50 * Normalise cookie data into a \WpOrg\Requests\Cookie33 * Normalise cookie data into a Requests_Cookie 51 34 * 52 * @param string| \WpOrg\Requests\Cookie $cookie53 * @return \WpOrg\Requests\Cookie35 * @param string|Requests_Cookie $cookie 36 * @return Requests_Cookie 54 37 */ 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) { 57 40 return $cookie; 58 41 } 59 42 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); 61 55 } 62 56 … … 64 58 * Check if the given item exists 65 59 * 66 * @param string $ offsetItem key60 * @param string $key Item key 67 61 * @return boolean Does the item exist? 68 62 */ 69 #[ReturnTypeWillChange] 70 public function offsetExists($offset) { 71 return isset($this->cookies[$offset]); 63 public function offsetExists($key) { 64 return isset($this->cookies[$key]); 72 65 } 73 66 … … 75 68 * Get the value for the item 76 69 * 77 * @param string $ offsetItem key70 * @param string $key Item key 78 71 * @return string|null Item value (null if offsetExists is false) 79 72 */ 80 #[ReturnTypeWillChange] 81 public function offsetGet($offset) { 82 if (!isset($this->cookies[$offset])) { 73 public function offsetGet($key) { 74 if (!isset($this->cookies[$key])) { 83 75 return null; 84 76 } 85 77 86 return $this->cookies[$ offset];78 return $this->cookies[$key]; 87 79 } 88 80 … … 90 82 * Set the given item 91 83 * 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 93 87 * @param string $value Item value 94 *95 * @throws \WpOrg\Requests\Exception On attempting to use dictionary as list (`invalidset`)96 88 */ 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'); 101 92 } 102 93 103 $this->cookies[$ offset] = $value;94 $this->cookies[$key] = $value; 104 95 } 105 96 … … 107 98 * Unset the given header 108 99 * 109 * @param string $ offset100 * @param string $key 110 101 */ 111 #[ReturnTypeWillChange] 112 public function offsetUnset($offset) { 113 unset($this->cookies[$offset]); 102 public function offsetUnset($key) { 103 unset($this->cookies[$key]); 114 104 } 115 105 … … 117 107 * Get an iterator for the data 118 108 * 119 * @return \ArrayIterator109 * @return ArrayIterator 120 110 */ 121 #[ReturnTypeWillChange]122 111 public function getIterator() { 123 112 return new ArrayIterator($this->cookies); … … 127 116 * Register the cookie handler with the request's hooking system 128 117 * 129 * @param \WpOrg\Requests\HookManager $hooks Hooking system118 * @param Requests_Hooker $hooks Hooking system 130 119 */ 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')); 134 123 } 135 124 … … 146 135 */ 147 136 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); 150 139 } 151 140 152 141 if (!empty($this->cookies)) { 153 $cookies = [];142 $cookies = array(); 154 143 foreach ($this->cookies as $key => $cookie) { 155 144 $cookie = $this->normalize_cookie($cookie, $key); … … 172 161 * Parse all cookies from a response and attach them to the response 173 162 * 174 * @ param \WpOrg\Requests\Response $response163 * @var Requests_Response $response 175 164 */ 176 public function before_redirect_check(Re sponse $response) {177 $url = $re sponse->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); 180 169 } 181 170 182 $cookies = Cookie::parse_from_headers($response->headers, $url);183 $this->cookies 184 $re sponse->cookies = $this;171 $cookies = Requests_Cookie::parse_from_headers($return->headers, $url); 172 $this->cookies = array_merge($this->cookies, $cookies); 173 $return->cookies = $this; 185 174 } 186 175 } -
trunk/src/wp-includes/Requests/Exception.php
r52244 r52328 3 3 * Exception for HTTP requests 4 4 * 5 * @package Requests \Exceptions5 * @package Requests 6 6 */ 7 8 namespace WpOrg\Requests;9 10 use Exception as PHPException;11 7 12 8 /** 13 9 * Exception for HTTP requests 14 10 * 15 * @package Requests \Exceptions11 * @package Requests 16 12 */ 17 class Exception extends PHPException {13 class Requests_Exception extends Exception { 18 14 /** 19 15 * Type of exception … … 46 42 47 43 /** 48 * Like {@see \Exception::getCode()}, but a string code.44 * Like {@see getCode()}, but a string code. 49 45 * 50 46 * @codeCoverageIgnore -
trunk/src/wp-includes/Requests/Exception/Transport.php
r52244 r52328 1 1 <?php 2 /**3 * Transport Exception4 *5 * @package Requests\Exceptions6 */7 2 8 namespace WpOrg\Requests\Exception; 3 class Requests_Exception_Transport extends Requests_Exception { 9 4 10 use WpOrg\Requests\Exception; 11 12 /** 13 * Transport Exception 14 * 15 * @package Requests\Exceptions 16 */ 17 class Transport extends Exception {} 5 } -
trunk/src/wp-includes/Requests/Hooks.php
r52244 r52328 3 3 * Handles adding and dispatching events 4 4 * 5 * @package Requests\EventDispatcher 5 * @package Requests 6 * @subpackage Utilities 6 7 */ 7 8 namespace WpOrg\Requests;9 10 use WpOrg\Requests\Exception\InvalidArgument;11 use WpOrg\Requests\HookManager;12 use WpOrg\Requests\Utility\InputValidator;13 8 14 9 /** 15 10 * Handles adding and dispatching events 16 11 * 17 * @package Requests\EventDispatcher 12 * @package Requests 13 * @subpackage Utilities 18 14 */ 19 class Hooks implements HookManager {15 class Requests_Hooks implements Requests_Hooker { 20 16 /** 21 17 * Registered callbacks for each hook … … 23 19 * @var array 24 20 */ 25 protected $hooks = []; 21 protected $hooks = array(); 22 23 /** 24 * Constructor 25 */ 26 public function __construct() { 27 // pass 28 } 26 29 27 30 /** … … 29 32 * 30 33 * @param string $hook Hook name 31 * @param call able$callback Function/method to call on event34 * @param callback $callback Function/method to call on event 32 35 * @param int $priority Priority number. <0 is executed earlier, >0 is executed later 33 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $hook argument is not a string.34 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $callback argument is not callable.35 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $priority argument is not an integer.36 36 */ 37 37 public function register($hook, $callback, $priority = 0) { 38 if ( is_string($hook) === false) {39 throw InvalidArgument::create(1, '$hook', 'string', gettype($hook));38 if (!isset($this->hooks[$hook])) { 39 $this->hooks[$hook] = array(); 40 40 } 41 42 if (is_callable($callback) === false) { 43 throw InvalidArgument::create(2, '$callback', 'callable', gettype($callback)); 44 } 45 46 if (InputValidator::is_numeric_array_key($priority) === false) { 47 throw InvalidArgument::create(3, '$priority', 'integer', gettype($priority)); 48 } 49 50 if (!isset($this->hooks[$hook])) { 51 $this->hooks[$hook] = [ 52 $priority => [], 53 ]; 54 } elseif (!isset($this->hooks[$hook][$priority])) { 55 $this->hooks[$hook][$priority] = []; 41 if (!isset($this->hooks[$hook][$priority])) { 42 $this->hooks[$hook][$priority] = array(); 56 43 } 57 44 … … 65 52 * @param array $parameters Parameters to pass to callbacks 66 53 * @return boolean Successfulness 67 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $hook argument is not a string.68 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $parameters argument is not an array.69 54 */ 70 public function dispatch($hook, $parameters = []) { 71 if (is_string($hook) === false) { 72 throw InvalidArgument::create(1, '$hook', 'string', gettype($hook)); 73 } 74 75 // Check strictly against array, as Array* objects don't work in combination with `call_user_func_array()`. 76 if (is_array($parameters) === false) { 77 throw InvalidArgument::create(2, '$parameters', 'array', gettype($parameters)); 78 } 79 55 public function dispatch($hook, $parameters = array()) { 80 56 if (empty($this->hooks[$hook])) { 81 57 return false; 82 58 } 83 59 84 if (!empty($parameters)) {85 // Strip potential keys from the array to prevent them being interpreted as parameter names in PHP 8.0.86 $parameters = array_values($parameters);87 }88 89 60 foreach ($this->hooks[$hook] as $priority => $hooked) { 90 61 foreach ($hooked as $callback) { 91 $callback(...$parameters);62 call_user_func_array($callback, $parameters); 92 63 } 93 64 } -
trunk/src/wp-includes/Requests/Proxy.php
r52244 r52328 3 3 * Proxy connection interface 4 4 * 5 * @package Requests\Proxy 6 * @since 1.6 5 * @package Requests 6 * @subpackage Proxy 7 * @since 1.6 7 8 */ 8 9 namespace WpOrg\Requests;10 11 use WpOrg\Requests\Hooks;12 9 13 10 /** … … 19 16 * makes it much easier for users to use your provider. 20 17 * 21 * @see \WpOrg\Requests\Hooks22 * 23 * @ package Requests\Proxy24 * @since 18 * @see Requests_Hooks 19 * @package Requests 20 * @subpackage Proxy 21 * @since 1.6 25 22 */ 26 interface Proxy {23 interface Requests_Proxy { 27 24 /** 28 25 * Register hooks as needed 29 26 * 30 * This method is called in {@see \WpOrg\Requests\Requests::request()} when the user31 * has setan instance as the 'auth' option. Use this callback to register all the27 * This method is called in {@see Requests::request} when the user has set 28 * an instance as the 'auth' option. Use this callback to register all the 32 29 * hooks you'll need. 33 30 * 34 * @see \WpOrg\Requests\Hooks::register()35 * @param \WpOrg\Requests\Hooks $hooks Hook system31 * @see Requests_Hooks::register 32 * @param Requests_Hooks $hooks Hook system 36 33 */ 37 public function register( Hooks $hooks);34 public function register(Requests_Hooks $hooks); 38 35 } -
trunk/src/wp-includes/Requests/Response.php
r52244 r52328 3 3 * HTTP response class 4 4 * 5 * Contains a response from \WpOrg\Requests\Requests::request() 6 * 5 * Contains a response from Requests::request() 7 6 * @package Requests 8 7 */ 9 10 namespace WpOrg\Requests;11 12 use WpOrg\Requests\Cookie\Jar;13 use WpOrg\Requests\Exception;14 use WpOrg\Requests\Exception\Http;15 use WpOrg\Requests\Response\Headers;16 8 17 9 /** 18 10 * HTTP response class 19 11 * 20 * Contains a response from \WpOrg\Requests\Requests::request() 21 * 12 * Contains a response from Requests::request() 22 13 * @package Requests 23 14 */ 24 class Response { 15 class Requests_Response { 16 /** 17 * Constructor 18 */ 19 public function __construct() { 20 $this->headers = new Requests_Response_Headers(); 21 $this->cookies = new Requests_Cookie_Jar(); 22 } 25 23 26 24 /** … … 41 39 * Headers, as an associative array 42 40 * 43 * @var \WpOrg\Requests\Response\Headers Array-like object representing headers41 * @var Requests_Response_Headers Array-like object representing headers 44 42 */ 45 public $headers = [];43 public $headers = array(); 46 44 47 45 /** … … 83 81 * Previous requests (from redirects) 84 82 * 85 * @var array Array of \WpOrg\Requests\Response objects83 * @var array Array of Requests_Response objects 86 84 */ 87 public $history = [];85 public $history = array(); 88 86 89 87 /** 90 88 * Cookies from the request 91 89 * 92 * @var \WpOrg\Requests\Cookie\Jar Array-like object representing a cookie jar90 * @var Requests_Cookie_Jar Array-like object representing a cookie jar 93 91 */ 94 public $cookies = []; 95 96 /** 97 * Constructor 98 */ 99 public function __construct() { 100 $this->headers = new Headers(); 101 $this->cookies = new Jar(); 102 } 92 public $cookies = array(); 103 93 104 94 /** … … 109 99 public function is_redirect() { 110 100 $code = $this->status_code; 111 return in_array($code, [300, 301, 302, 303, 307], true) || $code > 307 && $code < 400;101 return in_array($code, array(300, 301, 302, 303, 307), true) || $code > 307 && $code < 400; 112 102 } 113 103 … … 115 105 * Throws an exception if the request was not successful 116 106 * 107 * @throws Requests_Exception If `$allow_redirects` is false, and code is 3xx (`response.no_redirects`) 108 * @throws Requests_Exception_HTTP On non-successful status code. Exception class corresponds to code (e.g. {@see Requests_Exception_HTTP_404}) 117 109 * @param boolean $allow_redirects Set to false to throw on a 3xx as well 118 *119 * @throws \WpOrg\Requests\Exception If `$allow_redirects` is false, and code is 3xx (`response.no_redirects`)120 * @throws \WpOrg\Requests\Exception\Http On non-successful status code. Exception class corresponds to "Status" + code (e.g. {@see \WpOrg\Requests\Exception\Http\Status404})121 110 */ 122 111 public function throw_for_status($allow_redirects = true) { 123 112 if ($this->is_redirect()) { 124 if ( $allow_redirects !== true) {125 throw new Exception('Redirection not allowed', 'response.no_redirects', $this);113 if (!$allow_redirects) { 114 throw new Requests_Exception('Redirection not allowed', 'response.no_redirects', $this); 126 115 } 127 116 } 128 117 elseif (!$this->success) { 129 $exception = Http::get_class($this->status_code);118 $exception = Requests_Exception_HTTP::get_class($this->status_code); 130 119 throw new $exception(null, $this); 131 120 } 132 121 } 133 134 /**135 * JSON decode the response body.136 *137 * The method parameters are the same as those for the PHP native `json_decode()` function.138 *139 * @link https://php.net/json-decode140 *141 * @param ?bool $associative Optional. When `true`, JSON objects will be returned as associative arrays;142 * When `false`, JSON objects will be returned as objects.143 * When `null`, JSON objects will be returned as associative arrays144 * or objects depending on whether `JSON_OBJECT_AS_ARRAY` is set in the flags.145 * Defaults to `true` (in contrast to the PHP native default of `null`).146 * @param int $depth Optional. Maximum nesting depth of the structure being decoded.147 * Defaults to `512`.148 * @param int $options Optional. Bitmask of JSON_BIGINT_AS_STRING, JSON_INVALID_UTF8_IGNORE,149 * JSON_INVALID_UTF8_SUBSTITUTE, JSON_OBJECT_AS_ARRAY, JSON_THROW_ON_ERROR.150 * Defaults to `0` (no options set).151 *152 * @return array153 *154 * @throws \WpOrg\Requests\Exception If `$this->body` is not valid json.155 */156 public function decode_body($associative = true, $depth = 512, $options = 0) {157 $data = json_decode($this->body, $associative, $depth, $options);158 159 if (json_last_error() !== JSON_ERROR_NONE) {160 $last_error = json_last_error_msg();161 throw new Exception('Unable to parse JSON data: ' . $last_error, 'response.invalid', $this);162 }163 164 return $data;165 }166 122 } -
trunk/src/wp-includes/Requests/Response/Headers.php
r52244 r52328 6 6 */ 7 7 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 15 8 /** 16 9 * Case-insensitive dictionary, suitable for HTTP headers … … 18 11 * @package Requests 19 12 */ 20 class Headers extendsCaseInsensitiveDictionary {13 class Requests_Response_Headers extends Requests_Utility_CaseInsensitiveDictionary { 21 14 /** 22 15 * Get the given header 23 16 * 24 * Unlike {@see \WpOrg\Requests\Response\Headers::getValues()}, this returns a string. If there are17 * Unlike {@see self::getValues()}, this returns a string. If there are 25 18 * multiple values, it concatenates them with a comma as per RFC2616. 26 19 * … … 28 21 * Set-Cookie headers. 29 22 * 30 * @param string $ offset23 * @param string $key 31 24 * @return string|null Header value 32 25 */ 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])) { 39 29 return null; 40 30 } 41 31 42 return $this->flatten($this->data[$ offset]);32 return $this->flatten($this->data[$key]); 43 33 } 44 34 … … 46 36 * Set the given item 47 37 * 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 49 41 * @param string $value Item value 50 *51 * @throws \WpOrg\Requests\Exception On attempting to use dictionary as list (`invalidset`)52 42 */ 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'); 56 46 } 57 47 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(); 60 52 } 61 53 62 if (!isset($this->data[$offset])) { 63 $this->data[$offset] = []; 64 } 65 66 $this->data[$offset][] = $value; 54 $this->data[$key][] = $value; 67 55 } 68 56 … … 70 58 * Get all values for a given header 71 59 * 72 * @param string $ offset60 * @param string $key 73 61 * @return array|null Header values 74 *75 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not valid as an array key.76 62 */ 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])) { 84 66 return null; 85 67 } 86 68 87 return $this->data[$ offset];69 return $this->data[$key]; 88 70 } 89 71 … … 96 78 * @param string|array $value Value to flatten 97 79 * @return string Flattened value 98 *99 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not a string or an array.100 80 */ 101 81 public function flatten($value) { 102 if (is_ string($value)) {103 return $value;82 if (is_array($value)) { 83 $value = implode(',', $value); 104 84 } 105 85 106 if (is_array($value)) { 107 return implode(',', $value); 108 } 109 110 throw InvalidArgument::create(1, '$value', 'string|array', gettype($value)); 86 return $value; 111 87 } 112 88 … … 114 90 * Get an iterator for the data 115 91 * 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 120 94 */ 121 95 public function getIterator() { 122 return new FilteredIterator($this->data, [$this, 'flatten']);96 return new Requests_Utility_FilteredIterator($this->data, array($this, 'flatten')); 123 97 } 124 98 } -
trunk/src/wp-includes/Requests/Session.php
r52244 r52328 3 3 * Session handler for persistent requests and default parameters 4 4 * 5 * @package Requests\SessionHandler 5 * @package Requests 6 * @subpackage Session Handler 6 7 */ 7 8 namespace WpOrg\Requests;9 10 use WpOrg\Requests\Cookie\Jar;11 use WpOrg\Requests\Exception\InvalidArgument;12 use WpOrg\Requests\Iri;13 use WpOrg\Requests\Requests;14 use WpOrg\Requests\Utility\InputValidator;15 8 16 9 /** … … 22 15 * a shared cookie jar), then overridden for individual requests. 23 16 * 24 * @package Requests\SessionHandler 17 * @package Requests 18 * @subpackage Session Handler 25 19 */ 26 class Session {20 class Requests_Session { 27 21 /** 28 22 * Base URL for requests … … 39 33 * @var array 40 34 */ 41 public $headers = [];35 public $headers = array(); 42 36 43 37 /** … … 49 43 * @var array 50 44 */ 51 public $data = [];45 public $data = array(); 52 46 53 47 /** … … 62 56 * @var array 63 57 */ 64 public $options = [];58 public $options = array(); 65 59 66 60 /** 67 61 * Create a new session 68 62 * 69 * @param string| Stringable|null $url Base URL for requests63 * @param string|null $url Base URL for requests 70 64 * @param array $headers Default headers for requests 71 65 * @param array $data Default data for requests 72 66 * @param array $options Default options for requests 73 * 74 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $url argument is not a string, Stringable or null. 75 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $headers argument is not an array. 76 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $data argument is not an array. 77 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $options argument is not an array. 78 */ 79 public function __construct($url = null, $headers = [], $data = [], $options = []) { 80 if ($url !== null && InputValidator::is_string_or_stringable($url) === false) { 81 throw InvalidArgument::create(1, '$url', 'string|Stringable|null', gettype($url)); 82 } 83 84 if (is_array($headers) === false) { 85 throw InvalidArgument::create(2, '$headers', 'array', gettype($headers)); 86 } 87 88 if (is_array($data) === false) { 89 throw InvalidArgument::create(3, '$data', 'array', gettype($data)); 90 } 91 92 if (is_array($options) === false) { 93 throw InvalidArgument::create(4, '$options', 'array', gettype($options)); 94 } 95 67 */ 68 public function __construct($url = null, $headers = array(), $data = array(), $options = array()) { 96 69 $this->url = $url; 97 70 $this->headers = $headers; … … 100 73 101 74 if (empty($this->options['cookies'])) { 102 $this->options['cookies'] = new Jar();75 $this->options['cookies'] = new Requests_Cookie_Jar(); 103 76 } 104 77 } … … 107 80 * Get a property's value 108 81 * 109 * @param string $ name Property name.82 * @param string $key Property key 110 83 * @return mixed|null Property value, null if none found 111 84 */ 112 public function __get($ name) {113 if (isset($this->options[$ name])) {114 return $this->options[$ name];85 public function __get($key) { 86 if (isset($this->options[$key])) { 87 return $this->options[$key]; 115 88 } 116 89 … … 121 94 * Set a property's value 122 95 * 123 * @param string $ name Property name.96 * @param string $key Property key 124 97 * @param mixed $value Property value 125 98 */ 126 public function __set($ name, $value) {127 $this->options[$ name] = $value;99 public function __set($key, $value) { 100 $this->options[$key] = $value; 128 101 } 129 102 … … 131 104 * Remove a property's value 132 105 * 133 * @param string $ name Property name.134 */ 135 public function __isset($ name) {136 return isset($this->options[$ name]);106 * @param string $key Property key 107 */ 108 public function __isset($key) { 109 return isset($this->options[$key]); 137 110 } 138 111 … … 140 113 * Remove a property's value 141 114 * 142 * @param string $name Property name. 143 */ 144 public function __unset($name) { 145 unset($this->options[$name]); 115 * @param string $key Property key 116 */ 117 public function __unset($key) { 118 if (isset($this->options[$key])) { 119 unset($this->options[$key]); 120 } 146 121 } 147 122 148 123 /**#@+ 149 * @see \WpOrg\Requests\Session::request()124 * @see request() 150 125 * @param string $url 151 126 * @param array $headers 152 127 * @param array $options 153 * @return \WpOrg\Requests\Response128 * @return Requests_Response 154 129 */ 155 130 /** 156 131 * Send a GET request 157 132 */ 158 public function get($url, $headers = [], $options = []) {133 public function get($url, $headers = array(), $options = array()) { 159 134 return $this->request($url, $headers, null, Requests::GET, $options); 160 135 } … … 163 138 * Send a HEAD request 164 139 */ 165 public function head($url, $headers = [], $options = []) {140 public function head($url, $headers = array(), $options = array()) { 166 141 return $this->request($url, $headers, null, Requests::HEAD, $options); 167 142 } … … 170 145 * Send a DELETE request 171 146 */ 172 public function delete($url, $headers = [], $options = []) {147 public function delete($url, $headers = array(), $options = array()) { 173 148 return $this->request($url, $headers, null, Requests::DELETE, $options); 174 149 } … … 176 151 177 152 /**#@+ 178 * @see \WpOrg\Requests\Session::request()153 * @see request() 179 154 * @param string $url 180 155 * @param array $headers 181 156 * @param array $data 182 157 * @param array $options 183 * @return \WpOrg\Requests\Response158 * @return Requests_Response 184 159 */ 185 160 /** 186 161 * Send a POST request 187 162 */ 188 public function post($url, $headers = [], $data = [], $options = []) {163 public function post($url, $headers = array(), $data = array(), $options = array()) { 189 164 return $this->request($url, $headers, $data, Requests::POST, $options); 190 165 } … … 193 168 * Send a PUT request 194 169 */ 195 public function put($url, $headers = [], $data = [], $options = []) {170 public function put($url, $headers = array(), $data = array(), $options = array()) { 196 171 return $this->request($url, $headers, $data, Requests::PUT, $options); 197 172 } … … 200 175 * Send a PATCH request 201 176 * 202 * Note: Unlike {@see \WpOrg\Requests\Session::post()} and {@see \WpOrg\Requests\Session::put()},203 * `$headers` is required, as thespecification recommends that should send an ETag177 * Note: Unlike {@see post} and {@see put}, `$headers` is required, as the 178 * specification recommends that should send an ETag 204 179 * 205 180 * @link https://tools.ietf.org/html/rfc5789 206 181 */ 207 public function patch($url, $headers, $data = [], $options = []) {182 public function patch($url, $headers, $data = array(), $options = array()) { 208 183 return $this->request($url, $headers, $data, Requests::PATCH, $options); 209 184 } … … 216 191 * parsing. 217 192 * 218 * @see \WpOrg\Requests\Requests::request() 193 * @see Requests::request() 194 * 195 * @throws Requests_Exception On invalid URLs (`nonhttp`) 219 196 * 220 197 * @param string $url URL to request 221 198 * @param array $headers Extra headers to send with the request 222 199 * @param array|null $data Data to send either as a query string for GET/HEAD requests, or in the body for POST requests 223 * @param string $type HTTP request type (use \WpOrg\Requests\Requests constants) 224 * @param array $options Options for the request (see {@see \WpOrg\Requests\Requests::request()}) 225 * @return \WpOrg\Requests\Response 226 * 227 * @throws \WpOrg\Requests\Exception On invalid URLs (`nonhttp`) 228 */ 229 public function request($url, $headers = [], $data = [], $type = Requests::GET, $options = []) { 200 * @param string $type HTTP request type (use Requests constants) 201 * @param array $options Options for the request (see {@see Requests::request}) 202 * @return Requests_Response 203 */ 204 public function request($url, $headers = array(), $data = array(), $type = Requests::GET, $options = array()) { 230 205 $request = $this->merge_request(compact('url', 'headers', 'data', 'options')); 231 206 … … 236 211 * Send multiple HTTP requests simultaneously 237 212 * 238 * @see \WpOrg\Requests\Requests::request_multiple() 239 * 240 * @param array $requests Requests data (see {@see \WpOrg\Requests\Requests::request_multiple()}) 241 * @param array $options Global and default options (see {@see \WpOrg\Requests\Requests::request()}) 242 * @return array Responses (either \WpOrg\Requests\Response or a \WpOrg\Requests\Exception object) 243 * 244 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $requests argument is not an array or iterable object with array access. 245 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $options argument is not an array. 246 */ 247 public function request_multiple($requests, $options = []) { 248 if (InputValidator::has_array_access($requests) === false || InputValidator::is_iterable($requests) === false) { 249 throw InvalidArgument::create(1, '$requests', 'array|ArrayAccess&Traversable', gettype($requests)); 250 } 251 252 if (is_array($options) === false) { 253 throw InvalidArgument::create(2, '$options', 'array', gettype($options)); 254 } 255 213 * @see Requests::request_multiple() 214 * 215 * @param array $requests Requests data (see {@see Requests::request_multiple}) 216 * @param array $options Global and default options (see {@see Requests::request}) 217 * @return array Responses (either Requests_Response or a Requests_Exception object) 218 */ 219 public function request_multiple($requests, $options = array()) { 256 220 foreach ($requests as $key => $request) { 257 221 $requests[$key] = $this->merge_request($request, false); … … 269 233 * Merge a request's data with the default data 270 234 * 271 * @param array $request Request data (same form as {@see \WpOrg\Requests\Session::request_multiple()})235 * @param array $request Request data (same form as {@see request_multiple}) 272 236 * @param boolean $merge_options Should we merge options as well? 273 237 * @return array Request data … … 275 239 protected function merge_request($request, $merge_options = true) { 276 240 if ($this->url !== null) { 277 $request['url'] = Iri::absolutize($this->url, $request['url']);241 $request['url'] = Requests_IRI::absolutize($this->url, $request['url']); 278 242 $request['url'] = $request['url']->uri; 279 243 } 280 244 281 245 if (empty($request['headers'])) { 282 $request['headers'] = [];246 $request['headers'] = array(); 283 247 } 284 248 $request['headers'] = array_merge($this->headers, $request['headers']); … … 293 257 } 294 258 295 if ($merge_options === true) {259 if ($merge_options !== false) { 296 260 $request['options'] = array_merge($this->options, $request['options']); 297 261 -
trunk/src/wp-includes/Requests/Transport.php
r52244 r52328 3 3 * Base HTTP transport 4 4 * 5 * @package Requests\Transport 5 * @package Requests 6 * @subpackage Transport 6 7 */ 7 8 namespace WpOrg\Requests;9 8 10 9 /** 11 10 * Base HTTP transport 12 11 * 13 * @package Requests\Transport 12 * @package Requests 13 * @subpackage Transport 14 14 */ 15 interface Transport {15 interface Requests_Transport { 16 16 /** 17 17 * Perform a request … … 20 20 * @param array $headers Associative array of request headers 21 21 * @param string|array $data Data to send either as the POST body, or as parameters in the URL for a GET/HEAD 22 * @param array $options Request options, see {@see \WpOrg\Requests\Requests::response()} for documentation22 * @param array $options Request options, see {@see Requests::response()} for documentation 23 23 * @return string Raw HTTP result 24 24 */ 25 public function request($url, $headers = [], $data = [], $options = []);25 public function request($url, $headers = array(), $data = array(), $options = array()); 26 26 27 27 /** 28 28 * Send multiple requests simultaneously 29 29 * 30 * @param array $requests Request data (array of 'url', 'headers', 'data', 'options') as per {@see \WpOrg\Requests\Transport::request()}31 * @param array $options Global options, see {@see \WpOrg\Requests\Requests::response()} for documentation32 * @return array Array of \WpOrg\Requests\Response objects (may contain \WpOrg\Requests\Exception or string responses as well)30 * @param array $requests Request data (array of 'url', 'headers', 'data', 'options') as per {@see Requests_Transport::request} 31 * @param array $options Global options, see {@see Requests::response()} for documentation 32 * @return array Array of Requests_Response objects (may contain Requests_Exception or string responses as well) 33 33 */ 34 34 public function request_multiple($requests, $options); 35 35 36 36 /** 37 * Self-test whether the transport can be used. 38 * 39 * The available capabilities to test for can be found in {@see \WpOrg\Requests\Capability}. 40 * 41 * @param array<string, bool> $capabilities Optional. Associative array of capabilities to test against, i.e. `['<capability>' => true]`. 42 * @return bool Whether the transport can be used. 37 * Self-test whether the transport can be used 38 * @return bool 43 39 */ 44 public static function test( $capabilities = []);40 public static function test(); 45 41 } -
trunk/src/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php
r52244 r52328 3 3 * Case-insensitive dictionary, suitable for HTTP headers 4 4 * 5 * @package Requests\Utilities 5 * @package Requests 6 * @subpackage Utilities 6 7 */ 7 8 namespace WpOrg\Requests\Utility;9 10 use ArrayAccess;11 use ArrayIterator;12 use IteratorAggregate;13 use ReturnTypeWillChange;14 use WpOrg\Requests\Exception;15 8 16 9 /** 17 10 * Case-insensitive dictionary, suitable for HTTP headers 18 11 * 19 * @package Requests\Utilities 12 * @package Requests 13 * @subpackage Utilities 20 14 */ 21 class CaseInsensitiveDictionary implements ArrayAccess, IteratorAggregate {15 class Requests_Utility_CaseInsensitiveDictionary implements ArrayAccess, IteratorAggregate { 22 16 /** 23 17 * Actual item data … … 25 19 * @var array 26 20 */ 27 protected $data = [];21 protected $data = array(); 28 22 29 23 /** … … 32 26 * @param array $data Dictionary/map to convert to case-insensitive 33 27 */ 34 public function __construct(array $data = []) {35 foreach ($data as $ offset=> $value) {36 $this->offsetSet($ offset, $value);28 public function __construct(array $data = array()) { 29 foreach ($data as $key => $value) { 30 $this->offsetSet($key, $value); 37 31 } 38 32 } … … 41 35 * Check if the given item exists 42 36 * 43 * @param string $ offsetItem key37 * @param string $key Item key 44 38 * @return boolean Does the item exist? 45 39 */ 46 #[ReturnTypeWillChange] 47 public function offsetExists($offset) { 48 if (is_string($offset)) { 49 $offset = strtolower($offset); 50 } 51 52 return isset($this->data[$offset]); 40 public function offsetExists($key) { 41 $key = strtolower($key); 42 return isset($this->data[$key]); 53 43 } 54 44 … … 56 46 * Get the value for the item 57 47 * 58 * @param string $ offsetItem key59 * @return string|null Item value (null if the item key doesn't exist)48 * @param string $key Item key 49 * @return string|null Item value (null if offsetExists is false) 60 50 */ 61 #[ReturnTypeWillChange] 62 public function offsetGet($offset) { 63 if (is_string($offset)) { 64 $offset = strtolower($offset); 65 } 66 67 if (!isset($this->data[$offset])) { 51 public function offsetGet($key) { 52 $key = strtolower($key); 53 if (!isset($this->data[$key])) { 68 54 return null; 69 55 } 70 56 71 return $this->data[$ offset];57 return $this->data[$key]; 72 58 } 73 59 … … 75 61 * Set the given item 76 62 * 77 * @param string $offset Item name 63 * @throws Requests_Exception On attempting to use dictionary as list (`invalidset`) 64 * 65 * @param string $key Item name 78 66 * @param string $value Item value 79 *80 * @throws \WpOrg\Requests\Exception On attempting to use dictionary as list (`invalidset`)81 67 */ 82 #[ReturnTypeWillChange] 83 public function offsetSet($offset, $value) { 84 if ($offset === null) { 85 throw new Exception('Object is a dictionary, not a list', 'invalidset'); 68 public function offsetSet($key, $value) { 69 if ($key === null) { 70 throw new Requests_Exception('Object is a dictionary, not a list', 'invalidset'); 86 71 } 87 72 88 if (is_string($offset)) { 89 $offset = strtolower($offset); 90 } 91 92 $this->data[$offset] = $value; 73 $key = strtolower($key); 74 $this->data[$key] = $value; 93 75 } 94 76 … … 96 78 * Unset the given header 97 79 * 98 * @param string $ offset80 * @param string $key 99 81 */ 100 #[ReturnTypeWillChange] 101 public function offsetUnset($offset) { 102 if (is_string($offset)) { 103 $offset = strtolower($offset); 104 } 105 106 unset($this->data[$offset]); 82 public function offsetUnset($key) { 83 unset($this->data[strtolower($key)]); 107 84 } 108 85 … … 110 87 * Get an iterator for the data 111 88 * 112 * @return \ArrayIterator89 * @return ArrayIterator 113 90 */ 114 #[ReturnTypeWillChange]115 91 public function getIterator() { 116 92 return new ArrayIterator($this->data); -
trunk/src/wp-includes/Requests/Utility/FilteredIterator.php
r52244 r52328 3 3 * Iterator for arrays requiring filtered values 4 4 * 5 * @package Requests\Utilities 5 * @package Requests 6 * @subpackage Utilities 6 7 */ 7 8 namespace WpOrg\Requests\Utility;9 10 use ArrayIterator;11 use ReturnTypeWillChange;12 use WpOrg\Requests\Exception\InvalidArgument;13 use WpOrg\Requests\Utility\InputValidator;14 8 15 9 /** 16 10 * Iterator for arrays requiring filtered values 17 11 * 18 * @package Requests\Utilities 12 * @package Requests 13 * @subpackage Utilities 19 14 */ 20 final classFilteredIterator extends ArrayIterator {15 class Requests_Utility_FilteredIterator extends ArrayIterator { 21 16 /** 22 17 * Callback to run as a filter … … 24 19 * @var callable 25 20 */ 26 pr ivate$callback;21 protected $callback; 27 22 28 23 /** … … 31 26 * @param array $data 32 27 * @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.35 28 */ 36 29 public function __construct($data, $callback) { 37 if (InputValidator::is_iterable($data) === false) {38 throw InvalidArgument::create(1, '$data', 'iterable', gettype($data));39 }40 41 30 parent::__construct($data); 42 31 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); 32 $this->callback = $callback; 59 33 } 60 34 … … 64 38 * @return string 65 39 */ 66 #[ReturnTypeWillChange]67 40 public function current() { 68 41 $value = parent::current(); … … 78 51 * @inheritdoc 79 52 */ 80 #[ReturnTypeWillChange] 81 public function unserialize($data) {} 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 } 82 65 } -
trunk/src/wp-includes/class-requests.php
r52244 r52328 8 8 * 9 9 * @package Requests 10 *11 * @deprecated 5.9.012 10 */ 13 14 /*15 * Integrators who cannot yet upgrade to the PSR-4 class names can silence deprecations16 * by defining a `REQUESTS_SILENCE_PSR0_DEPRECATIONS` constant and setting it to `true`.17 * The constant needs to be defined before this class is required.18 */19 if (!defined('REQUESTS_SILENCE_PSR0_DEPRECATIONS') || REQUESTS_SILENCE_PSR0_DEPRECATIONS !== true) {20 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error21 trigger_error(22 'The PSR-0 `Requests_...` class names in the Request library are deprecated.'23 . ' Switch to the PSR-4 `WpOrg\Requests\...` class names at your earliest convenience.',24 E_USER_DEPRECATED25 );26 27 // Prevent the deprecation notice from being thrown twice.28 if (!defined('REQUESTS_SILENCE_PSR0_DEPRECATIONS')) {29 define('REQUESTS_SILENCE_PSR0_DEPRECATIONS', true);30 }31 }32 33 require_once __DIR__ . '/Requests/Requests.php';34 11 35 12 /** … … 41 18 * 42 19 * @package Requests 43 *44 * @deprecated 5.9.0 Use `WpOrg\Requests\Requests` instead for the actual functionality and45 * use `WpOrg\Requests\Autoload` for the autoloading.46 20 */ 47 class Requests extends WpOrg\Requests\Requests { 48 49 /** 50 * Deprecated autoloader for Requests. 51 * 52 * @deprecated 5.9.0 Use the `WpOrg\Requests\Autoload::load()` method instead. 21 class Requests { 22 /** 23 * POST method 24 * 25 * @var string 26 */ 27 const POST = 'POST'; 28 29 /** 30 * PUT method 31 * 32 * @var string 33 */ 34 const PUT = 'PUT'; 35 36 /** 37 * GET method 38 * 39 * @var string 40 */ 41 const GET = 'GET'; 42 43 /** 44 * HEAD method 45 * 46 * @var string 47 */ 48 const HEAD = 'HEAD'; 49 50 /** 51 * DELETE method 52 * 53 * @var string 54 */ 55 const DELETE = 'DELETE'; 56 57 /** 58 * OPTIONS method 59 * 60 * @var string 61 */ 62 const OPTIONS = 'OPTIONS'; 63 64 /** 65 * TRACE method 66 * 67 * @var string 68 */ 69 const TRACE = 'TRACE'; 70 71 /** 72 * PATCH method 73 * 74 * @link https://tools.ietf.org/html/rfc5789 75 * @var string 76 */ 77 const PATCH = 'PATCH'; 78 79 /** 80 * Default size of buffer size to read streams 81 * 82 * @var integer 83 */ 84 const BUFFER_SIZE = 1160; 85 86 /** 87 * Current version of Requests 88 * 89 * @var string 90 */ 91 const VERSION = '1.8.1'; 92 93 /** 94 * Registered transport classes 95 * 96 * @var array 97 */ 98 protected static $transports = array(); 99 100 /** 101 * Selected transport name 102 * 103 * Use {@see get_transport()} instead 104 * 105 * @var array 106 */ 107 public static $transport = array(); 108 109 /** 110 * Default certificate path. 111 * 112 * @see Requests::get_certificate_path() 113 * @see Requests::set_certificate_path() 114 * 115 * @var string 116 */ 117 protected static $certificate_path; 118 119 /** 120 * This is a static class, do not instantiate it 53 121 * 54 122 * @codeCoverageIgnore 123 */ 124 private function __construct() {} 125 126 /** 127 * Autoloader for Requests 128 * 129 * Register this with {@see register_autoloader()} if you'd like to avoid 130 * having to create your own. 131 * 132 * (You can also use `spl_autoload_register` directly if you'd prefer.) 133 * 134 * @codeCoverageIgnore 55 135 * 56 136 * @param string $class Class name to load 57 137 */ 58 138 public static function autoloader($class) { 59 if (class_exists('WpOrg\Requests\Autoload') === false) { 60 require_once __DIR__ . '/Requests/Autoload.php'; 61 } 62 63 return WpOrg\Requests\Autoload::load($class); 139 // Check that the class starts with "Requests" 140 if (strpos($class, 'Requests') !== 0) { 141 return; 142 } 143 144 $file = str_replace('_', '/', $class); 145 if (file_exists(dirname(__FILE__) . '/' . $file . '.php')) { 146 require_once dirname(__FILE__) . '/' . $file . '.php'; 147 } 64 148 } 65 149 … … 67 151 * Register the built-in autoloader 68 152 * 69 * @deprecated 5.9.0 Include the `WpOrg\Requests\Autoload` class and70 * call `WpOrg\Requests\Autoload::register()` instead.71 *72 153 * @codeCoverageIgnore 73 154 */ 74 155 public static function register_autoloader() { 75 require_once __DIR__ . '/Requests/Autoload.php'; 76 WpOrg\Requests\Autoload::register(); 156 spl_autoload_register(array('Requests', 'autoloader')); 157 } 158 159 /** 160 * Register a transport 161 * 162 * @param string $transport Transport class to add, must support the Requests_Transport interface 163 */ 164 public static function add_transport($transport) { 165 if (empty(self::$transports)) { 166 self::$transports = array( 167 'Requests_Transport_cURL', 168 'Requests_Transport_fsockopen', 169 ); 170 } 171 172 self::$transports = array_merge(self::$transports, array($transport)); 173 } 174 175 /** 176 * Get a working transport 177 * 178 * @throws Requests_Exception If no valid transport is found (`notransport`) 179 * @return Requests_Transport 180 */ 181 protected static function get_transport($capabilities = array()) { 182 // Caching code, don't bother testing coverage 183 // @codeCoverageIgnoreStart 184 // array of capabilities as a string to be used as an array key 185 ksort($capabilities); 186 $cap_string = serialize($capabilities); 187 188 // Don't search for a transport if it's already been done for these $capabilities 189 if (isset(self::$transport[$cap_string]) && self::$transport[$cap_string] !== null) { 190 $class = self::$transport[$cap_string]; 191 return new $class(); 192 } 193 // @codeCoverageIgnoreEnd 194 195 if (empty(self::$transports)) { 196 self::$transports = array( 197 'Requests_Transport_cURL', 198 'Requests_Transport_fsockopen', 199 ); 200 } 201 202 // Find us a working transport 203 foreach (self::$transports as $class) { 204 if (!class_exists($class)) { 205 continue; 206 } 207 208 $result = call_user_func(array($class, 'test'), $capabilities); 209 if ($result) { 210 self::$transport[$cap_string] = $class; 211 break; 212 } 213 } 214 if (self::$transport[$cap_string] === null) { 215 throw new Requests_Exception('No working transports found', 'notransport', self::$transports); 216 } 217 218 $class = self::$transport[$cap_string]; 219 return new $class(); 220 } 221 222 /**#@+ 223 * @see request() 224 * @param string $url 225 * @param array $headers 226 * @param array $options 227 * @return Requests_Response 228 */ 229 /** 230 * Send a GET request 231 */ 232 public static function get($url, $headers = array(), $options = array()) { 233 return self::request($url, $headers, null, self::GET, $options); 234 } 235 236 /** 237 * Send a HEAD request 238 */ 239 public static function head($url, $headers = array(), $options = array()) { 240 return self::request($url, $headers, null, self::HEAD, $options); 241 } 242 243 /** 244 * Send a DELETE request 245 */ 246 public static function delete($url, $headers = array(), $options = array()) { 247 return self::request($url, $headers, null, self::DELETE, $options); 248 } 249 250 /** 251 * Send a TRACE request 252 */ 253 public static function trace($url, $headers = array(), $options = array()) { 254 return self::request($url, $headers, null, self::TRACE, $options); 255 } 256 /**#@-*/ 257 258 /**#@+ 259 * @see request() 260 * @param string $url 261 * @param array $headers 262 * @param array $data 263 * @param array $options 264 * @return Requests_Response 265 */ 266 /** 267 * Send a POST request 268 */ 269 public static function post($url, $headers = array(), $data = array(), $options = array()) { 270 return self::request($url, $headers, $data, self::POST, $options); 271 } 272 /** 273 * Send a PUT request 274 */ 275 public static function put($url, $headers = array(), $data = array(), $options = array()) { 276 return self::request($url, $headers, $data, self::PUT, $options); 277 } 278 279 /** 280 * Send an OPTIONS request 281 */ 282 public static function options($url, $headers = array(), $data = array(), $options = array()) { 283 return self::request($url, $headers, $data, self::OPTIONS, $options); 284 } 285 286 /** 287 * Send a PATCH request 288 * 289 * Note: Unlike {@see post} and {@see put}, `$headers` is required, as the 290 * specification recommends that should send an ETag 291 * 292 * @link https://tools.ietf.org/html/rfc5789 293 */ 294 public static function patch($url, $headers, $data = array(), $options = array()) { 295 return self::request($url, $headers, $data, self::PATCH, $options); 296 } 297 /**#@-*/ 298 299 /** 300 * Main interface for HTTP requests 301 * 302 * This method initiates a request and sends it via a transport before 303 * parsing. 304 * 305 * The `$options` parameter takes an associative array with the following 306 * options: 307 * 308 * - `timeout`: How long should we wait for a response? 309 * Note: for cURL, a minimum of 1 second applies, as DNS resolution 310 * operates at second-resolution only. 311 * (float, seconds with a millisecond precision, default: 10, example: 0.01) 312 * - `connect_timeout`: How long should we wait while trying to connect? 313 * (float, seconds with a millisecond precision, default: 10, example: 0.01) 314 * - `useragent`: Useragent to send to the server 315 * (string, default: php-requests/$version) 316 * - `follow_redirects`: Should we follow 3xx redirects? 317 * (boolean, default: true) 318 * - `redirects`: How many times should we redirect before erroring? 319 * (integer, default: 10) 320 * - `blocking`: Should we block processing on this request? 321 * (boolean, default: true) 322 * - `filename`: File to stream the body to instead. 323 * (string|boolean, default: false) 324 * - `auth`: Authentication handler or array of user/password details to use 325 * for Basic authentication 326 * (Requests_Auth|array|boolean, default: false) 327 * - `proxy`: Proxy details to use for proxy by-passing and authentication 328 * (Requests_Proxy|array|string|boolean, default: false) 329 * - `max_bytes`: Limit for the response body size. 330 * (integer|boolean, default: false) 331 * - `idn`: Enable IDN parsing 332 * (boolean, default: true) 333 * - `transport`: Custom transport. Either a class name, or a 334 * transport object. Defaults to the first working transport from 335 * {@see getTransport()} 336 * (string|Requests_Transport, default: {@see getTransport()}) 337 * - `hooks`: Hooks handler. 338 * (Requests_Hooker, default: new Requests_Hooks()) 339 * - `verify`: Should we verify SSL certificates? Allows passing in a custom 340 * certificate file as a string. (Using true uses the system-wide root 341 * certificate store instead, but this may have different behaviour 342 * across transports.) 343 * (string|boolean, default: library/Requests/Transport/cacert.pem) 344 * - `verifyname`: Should we verify the common name in the SSL certificate? 345 * (boolean, default: true) 346 * - `data_format`: How should we send the `$data` parameter? 347 * (string, one of 'query' or 'body', default: 'query' for 348 * HEAD/GET/DELETE, 'body' for POST/PUT/OPTIONS/PATCH) 349 * 350 * @throws Requests_Exception On invalid URLs (`nonhttp`) 351 * 352 * @param string $url URL to request 353 * @param array $headers Extra headers to send with the request 354 * @param array|null $data Data to send either as a query string for GET/HEAD requests, or in the body for POST requests 355 * @param string $type HTTP request type (use Requests constants) 356 * @param array $options Options for the request (see description for more information) 357 * @return Requests_Response 358 */ 359 public static function request($url, $headers = array(), $data = array(), $type = self::GET, $options = array()) { 360 if (empty($options['type'])) { 361 $options['type'] = $type; 362 } 363 $options = array_merge(self::get_default_options(), $options); 364 365 self::set_defaults($url, $headers, $data, $type, $options); 366 367 $options['hooks']->dispatch('requests.before_request', array(&$url, &$headers, &$data, &$type, &$options)); 368 369 if (!empty($options['transport'])) { 370 $transport = $options['transport']; 371 372 if (is_string($options['transport'])) { 373 $transport = new $transport(); 374 } 375 } 376 else { 377 $need_ssl = (stripos($url, 'https://') === 0); 378 $capabilities = array('ssl' => $need_ssl); 379 $transport = self::get_transport($capabilities); 380 } 381 $response = $transport->request($url, $headers, $data, $options); 382 383 $options['hooks']->dispatch('requests.before_parse', array(&$response, $url, $headers, $data, $type, $options)); 384 385 return self::parse_response($response, $url, $headers, $data, $options); 386 } 387 388 /** 389 * Send multiple HTTP requests simultaneously 390 * 391 * The `$requests` parameter takes an associative or indexed array of 392 * request fields. The key of each request can be used to match up the 393 * request with the returned data, or with the request passed into your 394 * `multiple.request.complete` callback. 395 * 396 * The request fields value is an associative array with the following keys: 397 * 398 * - `url`: Request URL Same as the `$url` parameter to 399 * {@see Requests::request} 400 * (string, required) 401 * - `headers`: Associative array of header fields. Same as the `$headers` 402 * parameter to {@see Requests::request} 403 * (array, default: `array()`) 404 * - `data`: Associative array of data fields or a string. Same as the 405 * `$data` parameter to {@see Requests::request} 406 * (array|string, default: `array()`) 407 * - `type`: HTTP request type (use Requests constants). Same as the `$type` 408 * parameter to {@see Requests::request} 409 * (string, default: `Requests::GET`) 410 * - `cookies`: Associative array of cookie name to value, or cookie jar. 411 * (array|Requests_Cookie_Jar) 412 * 413 * If the `$options` parameter is specified, individual requests will 414 * inherit options from it. This can be used to use a single hooking system, 415 * or set all the types to `Requests::POST`, for example. 416 * 417 * In addition, the `$options` parameter takes the following global options: 418 * 419 * - `complete`: A callback for when a request is complete. Takes two 420 * parameters, a Requests_Response/Requests_Exception reference, and the 421 * ID from the request array (Note: this can also be overridden on a 422 * per-request basis, although that's a little silly) 423 * (callback) 424 * 425 * @param array $requests Requests data (see description for more information) 426 * @param array $options Global and default options (see {@see Requests::request}) 427 * @return array Responses (either Requests_Response or a Requests_Exception object) 428 */ 429 public static function request_multiple($requests, $options = array()) { 430 $options = array_merge(self::get_default_options(true), $options); 431 432 if (!empty($options['hooks'])) { 433 $options['hooks']->register('transport.internal.parse_response', array('Requests', 'parse_multiple')); 434 if (!empty($options['complete'])) { 435 $options['hooks']->register('multiple.request.complete', $options['complete']); 436 } 437 } 438 439 foreach ($requests as $id => &$request) { 440 if (!isset($request['headers'])) { 441 $request['headers'] = array(); 442 } 443 if (!isset($request['data'])) { 444 $request['data'] = array(); 445 } 446 if (!isset($request['type'])) { 447 $request['type'] = self::GET; 448 } 449 if (!isset($request['options'])) { 450 $request['options'] = $options; 451 $request['options']['type'] = $request['type']; 452 } 453 else { 454 if (empty($request['options']['type'])) { 455 $request['options']['type'] = $request['type']; 456 } 457 $request['options'] = array_merge($options, $request['options']); 458 } 459 460 self::set_defaults($request['url'], $request['headers'], $request['data'], $request['type'], $request['options']); 461 462 // Ensure we only hook in once 463 if ($request['options']['hooks'] !== $options['hooks']) { 464 $request['options']['hooks']->register('transport.internal.parse_response', array('Requests', 'parse_multiple')); 465 if (!empty($request['options']['complete'])) { 466 $request['options']['hooks']->register('multiple.request.complete', $request['options']['complete']); 467 } 468 } 469 } 470 unset($request); 471 472 if (!empty($options['transport'])) { 473 $transport = $options['transport']; 474 475 if (is_string($options['transport'])) { 476 $transport = new $transport(); 477 } 478 } 479 else { 480 $transport = self::get_transport(); 481 } 482 $responses = $transport->request_multiple($requests, $options); 483 484 foreach ($responses as $id => &$response) { 485 // If our hook got messed with somehow, ensure we end up with the 486 // correct response 487 if (is_string($response)) { 488 $request = $requests[$id]; 489 self::parse_multiple($response, $request); 490 $request['options']['hooks']->dispatch('multiple.request.complete', array(&$response, $id)); 491 } 492 } 493 494 return $responses; 495 } 496 497 /** 498 * Get the default options 499 * 500 * @see Requests::request() for values returned by this method 501 * @param boolean $multirequest Is this a multirequest? 502 * @return array Default option values 503 */ 504 protected static function get_default_options($multirequest = false) { 505 $defaults = array( 506 'timeout' => 10, 507 'connect_timeout' => 10, 508 'useragent' => 'php-requests/' . self::VERSION, 509 'protocol_version' => 1.1, 510 'redirected' => 0, 511 'redirects' => 10, 512 'follow_redirects' => true, 513 'blocking' => true, 514 'type' => self::GET, 515 'filename' => false, 516 'auth' => false, 517 'proxy' => false, 518 'cookies' => false, 519 'max_bytes' => false, 520 'idn' => true, 521 'hooks' => null, 522 'transport' => null, 523 'verify' => self::get_certificate_path(), 524 'verifyname' => true, 525 ); 526 if ($multirequest !== false) { 527 $defaults['complete'] = null; 528 } 529 return $defaults; 530 } 531 532 /** 533 * Get default certificate path. 534 * 535 * @return string Default certificate path. 536 */ 537 public static function get_certificate_path() { 538 if (!empty(self::$certificate_path)) { 539 return self::$certificate_path; 540 } 541 542 return dirname(__FILE__) . '/Requests/Transport/cacert.pem'; 543 } 544 545 /** 546 * Set default certificate path. 547 * 548 * @param string $path Certificate path, pointing to a PEM file. 549 */ 550 public static function set_certificate_path($path) { 551 self::$certificate_path = $path; 552 } 553 554 /** 555 * Set the default values 556 * 557 * @param string $url URL to request 558 * @param array $headers Extra headers to send with the request 559 * @param array|null $data Data to send either as a query string for GET/HEAD requests, or in the body for POST requests 560 * @param string $type HTTP request type 561 * @param array $options Options for the request 562 * @return array $options 563 */ 564 protected static function set_defaults(&$url, &$headers, &$data, &$type, &$options) { 565 if (!preg_match('/^http(s)?:\/\//i', $url, $matches)) { 566 throw new Requests_Exception('Only HTTP(S) requests are handled.', 'nonhttp', $url); 567 } 568 569 if (empty($options['hooks'])) { 570 $options['hooks'] = new Requests_Hooks(); 571 } 572 573 if (is_array($options['auth'])) { 574 $options['auth'] = new Requests_Auth_Basic($options['auth']); 575 } 576 if ($options['auth'] !== false) { 577 $options['auth']->register($options['hooks']); 578 } 579 580 if (is_string($options['proxy']) || is_array($options['proxy'])) { 581 $options['proxy'] = new Requests_Proxy_HTTP($options['proxy']); 582 } 583 if ($options['proxy'] !== false) { 584 $options['proxy']->register($options['hooks']); 585 } 586 587 if (is_array($options['cookies'])) { 588 $options['cookies'] = new Requests_Cookie_Jar($options['cookies']); 589 } 590 elseif (empty($options['cookies'])) { 591 $options['cookies'] = new Requests_Cookie_Jar(); 592 } 593 if ($options['cookies'] !== false) { 594 $options['cookies']->register($options['hooks']); 595 } 596 597 if ($options['idn'] !== false) { 598 $iri = new Requests_IRI($url); 599 $iri->host = Requests_IDNAEncoder::encode($iri->ihost); 600 $url = $iri->uri; 601 } 602 603 // Massage the type to ensure we support it. 604 $type = strtoupper($type); 605 606 if (!isset($options['data_format'])) { 607 if (in_array($type, array(self::HEAD, self::GET, self::DELETE), true)) { 608 $options['data_format'] = 'query'; 609 } 610 else { 611 $options['data_format'] = 'body'; 612 } 613 } 614 } 615 616 /** 617 * HTTP response parser 618 * 619 * @throws Requests_Exception On missing head/body separator (`requests.no_crlf_separator`) 620 * @throws Requests_Exception On missing head/body separator (`noversion`) 621 * @throws Requests_Exception On missing head/body separator (`toomanyredirects`) 622 * 623 * @param string $headers Full response text including headers and body 624 * @param string $url Original request URL 625 * @param array $req_headers Original $headers array passed to {@link request()}, in case we need to follow redirects 626 * @param array $req_data Original $data array passed to {@link request()}, in case we need to follow redirects 627 * @param array $options Original $options array passed to {@link request()}, in case we need to follow redirects 628 * @return Requests_Response 629 */ 630 protected static function parse_response($headers, $url, $req_headers, $req_data, $options) { 631 $return = new Requests_Response(); 632 if (!$options['blocking']) { 633 return $return; 634 } 635 636 $return->raw = $headers; 637 $return->url = (string) $url; 638 $return->body = ''; 639 640 if (!$options['filename']) { 641 $pos = strpos($headers, "\r\n\r\n"); 642 if ($pos === false) { 643 // Crap! 644 throw new Requests_Exception('Missing header/body separator', 'requests.no_crlf_separator'); 645 } 646 647 $headers = substr($return->raw, 0, $pos); 648 // Headers will always be separated from the body by two new lines - `\n\r\n\r`. 649 $body = substr($return->raw, $pos + 4); 650 if (!empty($body)) { 651 $return->body = $body; 652 } 653 } 654 // Pretend CRLF = LF for compatibility (RFC 2616, section 19.3) 655 $headers = str_replace("\r\n", "\n", $headers); 656 // Unfold headers (replace [CRLF] 1*( SP | HT ) with SP) as per RFC 2616 (section 2.2) 657 $headers = preg_replace('/\n[ \t]/', ' ', $headers); 658 $headers = explode("\n", $headers); 659 preg_match('#^HTTP/(1\.\d)[ \t]+(\d+)#i', array_shift($headers), $matches); 660 if (empty($matches)) { 661 throw new Requests_Exception('Response could not be parsed', 'noversion', $headers); 662 } 663 $return->protocol_version = (float) $matches[1]; 664 $return->status_code = (int) $matches[2]; 665 if ($return->status_code >= 200 && $return->status_code < 300) { 666 $return->success = true; 667 } 668 669 foreach ($headers as $header) { 670 list($key, $value) = explode(':', $header, 2); 671 $value = trim($value); 672 preg_replace('#(\s+)#i', ' ', $value); 673 $return->headers[$key] = $value; 674 } 675 if (isset($return->headers['transfer-encoding'])) { 676 $return->body = self::decode_chunked($return->body); 677 unset($return->headers['transfer-encoding']); 678 } 679 if (isset($return->headers['content-encoding'])) { 680 $return->body = self::decompress($return->body); 681 } 682 683 //fsockopen and cURL compatibility 684 if (isset($return->headers['connection'])) { 685 unset($return->headers['connection']); 686 } 687 688 $options['hooks']->dispatch('requests.before_redirect_check', array(&$return, $req_headers, $req_data, $options)); 689 690 if ($return->is_redirect() && $options['follow_redirects'] === true) { 691 if (isset($return->headers['location']) && $options['redirected'] < $options['redirects']) { 692 if ($return->status_code === 303) { 693 $options['type'] = self::GET; 694 } 695 $options['redirected']++; 696 $location = $return->headers['location']; 697 if (strpos($location, 'http://') !== 0 && strpos($location, 'https://') !== 0) { 698 // relative redirect, for compatibility make it absolute 699 $location = Requests_IRI::absolutize($url, $location); 700 $location = $location->uri; 701 } 702 703 $hook_args = array( 704 &$location, 705 &$req_headers, 706 &$req_data, 707 &$options, 708 $return, 709 ); 710 $options['hooks']->dispatch('requests.before_redirect', $hook_args); 711 $redirected = self::request($location, $req_headers, $req_data, $options['type'], $options); 712 $redirected->history[] = $return; 713 return $redirected; 714 } 715 elseif ($options['redirected'] >= $options['redirects']) { 716 throw new Requests_Exception('Too many redirects', 'toomanyredirects', $return); 717 } 718 } 719 720 $return->redirects = $options['redirected']; 721 722 $options['hooks']->dispatch('requests.after_request', array(&$return, $req_headers, $req_data, $options)); 723 return $return; 724 } 725 726 /** 727 * Callback for `transport.internal.parse_response` 728 * 729 * Internal use only. Converts a raw HTTP response to a Requests_Response 730 * while still executing a multiple request. 731 * 732 * @param string $response Full response text including headers and body (will be overwritten with Response instance) 733 * @param array $request Request data as passed into {@see Requests::request_multiple()} 734 * @return null `$response` is either set to a Requests_Response instance, or a Requests_Exception object 735 */ 736 public static function parse_multiple(&$response, $request) { 737 try { 738 $url = $request['url']; 739 $headers = $request['headers']; 740 $data = $request['data']; 741 $options = $request['options']; 742 $response = self::parse_response($response, $url, $headers, $data, $options); 743 } 744 catch (Requests_Exception $e) { 745 $response = $e; 746 } 747 } 748 749 /** 750 * Decoded a chunked body as per RFC 2616 751 * 752 * @see https://tools.ietf.org/html/rfc2616#section-3.6.1 753 * @param string $data Chunked body 754 * @return string Decoded body 755 */ 756 protected static function decode_chunked($data) { 757 if (!preg_match('/^([0-9a-f]+)(?:;(?:[\w-]*)(?:=(?:(?:[\w-]*)*|"(?:[^\r\n])*"))?)*\r\n/i', trim($data))) { 758 return $data; 759 } 760 761 $decoded = ''; 762 $encoded = $data; 763 764 while (true) { 765 $is_chunked = (bool) preg_match('/^([0-9a-f]+)(?:;(?:[\w-]*)(?:=(?:(?:[\w-]*)*|"(?:[^\r\n])*"))?)*\r\n/i', $encoded, $matches); 766 if (!$is_chunked) { 767 // Looks like it's not chunked after all 768 return $data; 769 } 770 771 $length = hexdec(trim($matches[1])); 772 if ($length === 0) { 773 // Ignore trailer headers 774 return $decoded; 775 } 776 777 $chunk_length = strlen($matches[0]); 778 $decoded .= substr($encoded, $chunk_length, $length); 779 $encoded = substr($encoded, $chunk_length + $length + 2); 780 781 if (trim($encoded) === '0' || empty($encoded)) { 782 return $decoded; 783 } 784 } 785 786 // We'll never actually get down here 787 // @codeCoverageIgnoreStart 788 } 789 // @codeCoverageIgnoreEnd 790 791 /** 792 * Convert a key => value array to a 'key: value' array for headers 793 * 794 * @param array $array Dictionary of header values 795 * @return array List of headers 796 */ 797 public static function flatten($array) { 798 $return = array(); 799 foreach ($array as $key => $value) { 800 $return[] = sprintf('%s: %s', $key, $value); 801 } 802 return $return; 803 } 804 805 /** 806 * Convert a key => value array to a 'key: value' array for headers 807 * 808 * @codeCoverageIgnore 809 * @deprecated Misspelling of {@see Requests::flatten} 810 * @param array $array Dictionary of header values 811 * @return array List of headers 812 */ 813 public static function flattern($array) { 814 return self::flatten($array); 815 } 816 817 /** 818 * Decompress an encoded body 819 * 820 * Implements gzip, compress and deflate. Guesses which it is by attempting 821 * to decode. 822 * 823 * @param string $data Compressed data in one of the above formats 824 * @return string Decompressed string 825 */ 826 public static function decompress($data) { 827 if (substr($data, 0, 2) !== "\x1f\x8b" && substr($data, 0, 2) !== "\x78\x9c") { 828 // Not actually compressed. Probably cURL ruining this for us. 829 return $data; 830 } 831 832 if (function_exists('gzdecode')) { 833 // phpcs:ignore PHPCompatibility.FunctionUse.NewFunctions.gzdecodeFound -- Wrapped in function_exists() for PHP 5.2. 834 $decoded = @gzdecode($data); 835 if ($decoded !== false) { 836 return $decoded; 837 } 838 } 839 840 if (function_exists('gzinflate')) { 841 $decoded = @gzinflate($data); 842 if ($decoded !== false) { 843 return $decoded; 844 } 845 } 846 847 $decoded = self::compatible_gzinflate($data); 848 if ($decoded !== false) { 849 return $decoded; 850 } 851 852 if (function_exists('gzuncompress')) { 853 $decoded = @gzuncompress($data); 854 if ($decoded !== false) { 855 return $decoded; 856 } 857 } 858 859 return $data; 860 } 861 862 /** 863 * Decompression of deflated string while staying compatible with the majority of servers. 864 * 865 * Certain Servers will return deflated data with headers which PHP's gzinflate() 866 * function cannot handle out of the box. The following function has been created from 867 * various snippets on the gzinflate() PHP documentation. 868 * 869 * Warning: Magic numbers within. Due to the potential different formats that the compressed 870 * data may be returned in, some "magic offsets" are needed to ensure proper decompression 871 * takes place. For a simple progmatic way to determine the magic offset in use, see: 872 * https://core.trac.wordpress.org/ticket/18273 873 * 874 * @since 2.8.1 875 * @link https://core.trac.wordpress.org/ticket/18273 876 * @link https://secure.php.net/manual/en/function.gzinflate.php#70875 877 * @link https://secure.php.net/manual/en/function.gzinflate.php#77336 878 * 879 * @param string $gz_data String to decompress. 880 * @return string|bool False on failure. 881 */ 882 public static function compatible_gzinflate($gz_data) { 883 // Compressed data might contain a full zlib header, if so strip it for 884 // gzinflate() 885 if (substr($gz_data, 0, 3) === "\x1f\x8b\x08") { 886 $i = 10; 887 $flg = ord(substr($gz_data, 3, 1)); 888 if ($flg > 0) { 889 if ($flg & 4) { 890 list($xlen) = unpack('v', substr($gz_data, $i, 2)); 891 $i += 2 + $xlen; 892 } 893 if ($flg & 8) { 894 $i = strpos($gz_data, "\0", $i) + 1; 895 } 896 if ($flg & 16) { 897 $i = strpos($gz_data, "\0", $i) + 1; 898 } 899 if ($flg & 2) { 900 $i += 2; 901 } 902 } 903 $decompressed = self::compatible_gzinflate(substr($gz_data, $i)); 904 if ($decompressed !== false) { 905 return $decompressed; 906 } 907 } 908 909 // If the data is Huffman Encoded, we must first strip the leading 2 910 // byte Huffman marker for gzinflate() 911 // The response is Huffman coded by many compressors such as 912 // java.util.zip.Deflater, Ruby’s Zlib::Deflate, and .NET's 913 // System.IO.Compression.DeflateStream. 914 // 915 // See https://decompres.blogspot.com/ for a quick explanation of this 916 // data type 917 $huffman_encoded = false; 918 919 // low nibble of first byte should be 0x08 920 list(, $first_nibble) = unpack('h', $gz_data); 921 922 // First 2 bytes should be divisible by 0x1F 923 list(, $first_two_bytes) = unpack('n', $gz_data); 924 925 if ($first_nibble === 0x08 && ($first_two_bytes % 0x1F) === 0) { 926 $huffman_encoded = true; 927 } 928 929 if ($huffman_encoded) { 930 $decompressed = @gzinflate(substr($gz_data, 2)); 931 if ($decompressed !== false) { 932 return $decompressed; 933 } 934 } 935 936 if (substr($gz_data, 0, 4) === "\x50\x4b\x03\x04") { 937 // ZIP file format header 938 // Offset 6: 2 bytes, General-purpose field 939 // Offset 26: 2 bytes, filename length 940 // Offset 28: 2 bytes, optional field length 941 // Offset 30: Filename field, followed by optional field, followed 942 // immediately by data 943 list(, $general_purpose_flag) = unpack('v', substr($gz_data, 6, 2)); 944 945 // If the file has been compressed on the fly, 0x08 bit is set of 946 // the general purpose field. We can use this to differentiate 947 // between a compressed document, and a ZIP file 948 $zip_compressed_on_the_fly = ((0x08 & $general_purpose_flag) === 0x08); 949 950 if (!$zip_compressed_on_the_fly) { 951 // Don't attempt to decode a compressed zip file 952 return $gz_data; 953 } 954 955 // Determine the first byte of data, based on the above ZIP header 956 // offsets: 957 $first_file_start = array_sum(unpack('v2', substr($gz_data, 26, 4))); 958 $decompressed = @gzinflate(substr($gz_data, 30 + $first_file_start)); 959 if ($decompressed !== false) { 960 return $decompressed; 961 } 962 return false; 963 } 964 965 // Finally fall back to straight gzinflate 966 $decompressed = @gzinflate($gz_data); 967 if ($decompressed !== false) { 968 return $decompressed; 969 } 970 971 // Fallback for all above failing, not expected, but included for 972 // debugging and preventing regressions and to track stats 973 $decompressed = @gzinflate(substr($gz_data, 2)); 974 if ($decompressed !== false) { 975 return $decompressed; 976 } 977 978 return false; 979 } 980 981 public static function match_domain($host, $reference) { 982 // Check for a direct match 983 if ($host === $reference) { 984 return true; 985 } 986 987 // Calculate the valid wildcard match if the host is not an IP address 988 // Also validates that the host has 3 parts or more, as per Firefox's 989 // ruleset. 990 $parts = explode('.', $host); 991 if (ip2long($host) === false && count($parts) >= 3) { 992 $parts[0] = '*'; 993 $wildcard = implode('.', $parts); 994 if ($wildcard === $reference) { 995 return true; 996 } 997 } 998 999 return false; 77 1000 } 78 1001 } -
trunk/src/wp-includes/class-wp-http-requests-hooks.php
r52244 r52328 13 13 * @since 4.7.0 14 14 * 15 * @see WpOrg\Requests\Hooks15 * @see Requests_Hooks 16 16 */ 17 class WP_HTTP_Requests_Hooks extends WpOrg\Requests\Hooks {17 class WP_HTTP_Requests_Hooks extends Requests_Hooks { 18 18 /** 19 19 * Requested URL. -
trunk/src/wp-includes/class-wp-http-requests-response.php
r52244 r52328 9 9 10 10 /** 11 * Core wrapper object for a WpOrg\Requests\Response for standardisation.11 * Core wrapper object for a Requests_Response for standardisation. 12 12 * 13 13 * @since 4.6.0 … … 20 20 * 21 21 * @since 4.6.0 22 * @var \WpOrg\Requests\Response22 * @var Requests_Response 23 23 */ 24 24 protected $response; … … 37 37 * @since 4.6.0 38 38 * 39 * @param \WpOrg\Requests\Response $response HTTP response.40 * @param string 39 * @param Requests_Response $response HTTP response. 40 * @param string $filename Optional. File name. Default empty. 41 41 */ 42 public function __construct( WpOrg\Requests\Response $response, $filename = '' ) {42 public function __construct( Requests_Response $response, $filename = '' ) { 43 43 $this->response = $response; 44 44 $this->filename = $filename; … … 50 50 * @since 4.6.0 51 51 * 52 * @return WpOrg\Requests\Response HTTP response.52 * @return Requests_Response HTTP response. 53 53 */ 54 54 public function get_response_object() { … … 61 61 * @since 4.6.0 62 62 * 63 * @return \ WpOrg\Requests\Utility\CaseInsensitiveDictionary Map of header name to header value.63 * @return \Requests_Utility_CaseInsensitiveDictionary Map of header name to header value. 64 64 */ 65 65 public function get_headers() { 66 66 // Ensure headers remain case-insensitive. 67 $converted = new WpOrg\Requests\Utility\CaseInsensitiveDictionary();67 $converted = new Requests_Utility_CaseInsensitiveDictionary(); 68 68 69 69 foreach ( $this->response->headers->getAll() as $key => $value ) { … … 86 86 */ 87 87 public function set_headers( $headers ) { 88 $this->response->headers = new WpOrg\Requests\Response\Headers( $headers );88 $this->response->headers = new Requests_Response_Headers( $headers ); 89 89 } 90 90 -
trunk/src/wp-includes/class-wp-http.php
r52327 r52328 8 8 */ 9 9 10 if ( ! class_exists( ' WpOrg\Requests\Autoload' ) ) {11 require ABSPATH . WPINC . '/ Requests/Autoload.php';12 13 WpOrg\Requests\Autoload::register();14 WpOrg\Requests\Requests::set_certificate_path( ABSPATH . WPINC . '/certificates/ca-bundle.crt' );10 if ( ! class_exists( 'Requests' ) ) { 11 require ABSPATH . WPINC . '/class-requests.php'; 12 13 Requests::register_autoloader(); 14 Requests::set_certificate_path( ABSPATH . WPINC . '/certificates/ca-bundle.crt' ); 15 15 } 16 16 … … 275 275 $response = new WP_Error( 'http_request_failed', __( 'A valid URL was not provided.' ) ); 276 276 /** This action is documented in wp-includes/class-wp-http.php */ 277 do_action( 'http_api_debug', $response, 'response', ' WpOrg\Requests\Requests', $parsed_args, $url );277 do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url ); 278 278 return $response; 279 279 } … … 282 282 $response = new WP_Error( 'http_request_not_executed', __( 'User has blocked requests through HTTP.' ) ); 283 283 /** This action is documented in wp-includes/class-wp-http.php */ 284 do_action( 'http_api_debug', $response, 'response', ' WpOrg\Requests\Requests', $parsed_args, $url );284 do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url ); 285 285 return $response; 286 286 } … … 299 299 $response = new WP_Error( 'http_request_failed', __( 'Destination directory for file streaming does not exist or is not writable.' ) ); 300 300 /** This action is documented in wp-includes/class-wp-http.php */ 301 do_action( 'http_api_debug', $response, 'response', ' WpOrg\Requests\Requests', $parsed_args, $url );301 do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url ); 302 302 return $response; 303 303 } … … 347 347 } 348 348 349 // If we've got cookies, use and convert them to WpOrg\Requests\Cookie.349 // If we've got cookies, use and convert them to Requests_Cookie. 350 350 if ( ! empty( $parsed_args['cookies'] ) ) { 351 351 $options['cookies'] = WP_Http::normalize_cookies( $parsed_args['cookies'] ); … … 379 379 $proxy = new WP_HTTP_Proxy(); 380 380 if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) { 381 $options['proxy'] = new WpOrg\Requests\Proxy\HTTP( $proxy->host() . ':' . $proxy->port() );381 $options['proxy'] = new Requests_Proxy_HTTP( $proxy->host() . ':' . $proxy->port() ); 382 382 383 383 if ( $proxy->use_authentication() ) { … … 392 392 393 393 try { 394 $requests_response = WpOrg\Requests\Requests::request( $url, $headers, $data, $type, $options );394 $requests_response = Requests::request( $url, $headers, $data, $type, $options ); 395 395 396 396 // Convert the response into an array. … … 400 400 // Add the original object to the array. 401 401 $response['http_response'] = $http_response; 402 } catch ( WpOrg\Requests\Exception $e ) {402 } catch ( Requests_Exception $e ) { 403 403 $response = new WP_Error( 'http_request_failed', $e->getMessage() ); 404 404 } … … 417 417 * @param string $url The request URL. 418 418 */ 419 do_action( 'http_api_debug', $response, 'response', ' WpOrg\Requests\Requests', $parsed_args, $url );419 do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url ); 420 420 if ( is_wp_error( $response ) ) { 421 421 return $response; … … 453 453 * 454 454 * @param array $cookies Array of cookies to send with the request. 455 * @return WpOrg\Requests\Cookie\Jar Cookie holder object.455 * @return Requests_Cookie_Jar Cookie holder object. 456 456 */ 457 457 public static function normalize_cookies( $cookies ) { 458 $cookie_jar = new WpOrg\Requests\Cookie\Jar();458 $cookie_jar = new Requests_Cookie_Jar(); 459 459 460 460 foreach ( $cookies as $name => $value ) { … … 466 466 } 467 467 ); 468 $cookie_jar[ $value->name ] = new WpOrg\Requests\Cookie( $value->name, $value->value, $attributes, array( 'host-only' => $value->host_only ) );468 $cookie_jar[ $value->name ] = new Requests_Cookie( $value->name, $value->value, $attributes, array( 'host-only' => $value->host_only ) ); 469 469 } elseif ( is_scalar( $value ) ) { 470 $cookie_jar[ $name ] = new WpOrg\Requests\Cookie( $name, (string)$value );470 $cookie_jar[ $name ] = new Requests_Cookie( $name, $value ); 471 471 } 472 472 } … … 484 484 * @since 4.6.0 485 485 * 486 * @param string 487 * @param array 488 * @param string|array 489 * @param array 490 * @param WpOrg\Requests\Response $original Response object.486 * @param string $location URL to redirect to. 487 * @param array $headers Headers for the redirect. 488 * @param string|array $data Body to send with the request. 489 * @param array $options Redirect request options. 490 * @param Requests_Response $original Response object. 491 491 */ 492 492 public static function browser_redirect_compatibility( $location, $headers, $data, &$options, $original ) { 493 493 // Browser compatibility. 494 494 if ( 302 === $original->status_code ) { 495 $options['type'] = WpOrg\Requests\Requests::GET;495 $options['type'] = Requests::GET; 496 496 } 497 497 } … … 502 502 * @since 4.7.5 503 503 * 504 * @throws WpOrg\Requests\Exception On unsuccessful URL validation.504 * @throws Requests_Exception On unsuccessful URL validation. 505 505 * @param string $location URL to redirect to. 506 506 */ 507 507 public static function validate_redirects( $location ) { 508 508 if ( ! wp_http_validate_url( $location ) ) { 509 throw new WpOrg\Requests\Exception( __( 'A valid URL was not provided.' ), 'wp_http.redirect_failed_validation' );509 throw new Requests_Exception( __( 'A valid URL was not provided.' ), 'wp_http.redirect_failed_validation' ); 510 510 } 511 511 } -
trunk/src/wp-includes/http.php
r52244 r52328 201 201 * 202 202 * @since 2.7.0 203 * @since 4.6.0 Return value changed from an array to an WpOrg\Requests\Utility\CaseInsensitiveDictionary instance.204 * 205 * @see \ WpOrg\Requests\Utility\CaseInsensitiveDictionary203 * @since 4.6.0 Return value changed from an array to an Requests_Utility_CaseInsensitiveDictionary instance. 204 * 205 * @see \Requests_Utility_CaseInsensitiveDictionary 206 206 * 207 207 * @param array|WP_Error $response HTTP response. 208 * @return array|\ WpOrg\Requests\Utility\CaseInsensitiveDictionary The headers of the response. Empty array if incorrect parameter given.208 * @return array|\Requests_Utility_CaseInsensitiveDictionary The headers of the response. Empty array if incorrect parameter given. 209 209 */ 210 210 function wp_remote_retrieve_headers( $response ) { -
trunk/src/wp-includes/rest-api.php
r52286 r52328 1391 1391 $ipv4_pattern = '/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/'; 1392 1392 1393 if ( ! preg_match( $ipv4_pattern, $ip ) && ! WpOrg\Requests\Ipv6::check_ipv6( $ip ) ) {1393 if ( ! preg_match( $ipv4_pattern, $ip ) && ! Requests_IPv6::check_ipv6( $ip ) ) { 1394 1394 return false; 1395 1395 } -
trunk/tests/phpunit/tests/feed/wpSimplePieFile.php
r52244 r52328 86 86 87 87 return array( 88 'headers' => new WpOrg\Requests\Utility\CaseInsensitiveDictionary( $single_value_headers ),88 'headers' => new Requests_Utility_CaseInsensitiveDictionary( $single_value_headers ), 89 89 'body' => file_get_contents( DIR_TESTDATA . '/feed/wordpress-org-news.xml' ), 90 90 'response' => array( … … 115 115 ); 116 116 117 $response['headers'] = new WpOrg\Requests\Utility\CaseInsensitiveDictionary( $multiple_value_headers );117 $response['headers'] = new Requests_Utility_CaseInsensitiveDictionary( $multiple_value_headers ); 118 118 119 119 return $response; -
trunk/tests/phpunit/tests/functions.php
r52244 r52328 365 365 public function test_deserialize_request_utility_filtered_iterator_objects( $value ) { 366 366 $serialized = maybe_serialize( $value ); 367 if ( get_class( $value ) === ' WpOrg\Requests\Utility\FilteredIterator' ) {367 if ( get_class( $value ) === 'Requests_Utility_FilteredIterator' ) { 368 368 $new_value = unserialize( $serialized ); 369 $property = ( new ReflectionClass( ' WpOrg\Requests\Utility\FilteredIterator' ) )->getProperty( 'callback' );369 $property = ( new ReflectionClass( 'Requests_Utility_FilteredIterator' ) )->getProperty( 'callback' ); 370 370 $property->setAccessible( true ); 371 371 $callback_value = $property->getValue( $new_value ); … … 378 378 public function data_serialize_deserialize_objects() { 379 379 return array( 380 array( new WpOrg\Requests\Utility\FilteredIterator( array( 1 ), 'md5' ) ),381 array( new WpOrg\Requests\Utility\FilteredIterator( array( 1, 2 ), 'sha1' ) ),380 array( new Requests_Utility_FilteredIterator( array( 1 ), 'md5' ) ), 381 array( new Requests_Utility_FilteredIterator( array( 1, 2 ), 'sha1' ) ), 382 382 array( new ArrayIterator( array( 1, 2, 3 ) ) ), 383 383 ); -
trunk/tests/phpunit/tests/http/functions.php
r52244 r52328 217 217 public function test_get_cookie_host_only() { 218 218 // Emulate WP_Http::request() internals. 219 $requests_response = new WpOrg\Requests\Response();220 221 $requests_response->cookies['test'] = WpOrg\Requests\Cookie::parse( 'test=foo; domain=.wordpress.org' );219 $requests_response = new Requests_Response(); 220 221 $requests_response->cookies['test'] = Requests_Cookie::parse( 'test=foo; domain=.wordpress.org' ); 222 222 223 223 $requests_response->cookies['test']->flags['host-only'] = false; // https://github.com/WordPress/Requests/issues/306 … … 232 232 $this->assertFalse( $cookie->host_only, 'host-only flag not set' ); 233 233 234 // Regurgitate ( WpOrg\Requests\Cookie -> WP_Http_Cookie -> WpOrg\Requests\Cookie).234 // Regurgitate (Requests_Cookie -> WP_Http_Cookie -> Requests_Cookie). 235 235 $cookies = WP_Http::normalize_cookies( wp_remote_retrieve_cookies( $response ) ); 236 236 $this->assertFalse( $cookies['test']->flags['host-only'], 'host-only flag data lost' ); -
trunk/tests/phpunit/tests/http/http.php
r52244 r52328 310 310 ); 311 311 312 $this->assertInstanceOf( ' WpOrg\Requests\Cookie\Jar', $cookie_jar );312 $this->assertInstanceOf( 'Requests_Cookie_Jar', $cookie_jar ); 313 313 314 314 foreach ( array_keys( $cookies ) as $cookie ) { … … 316 316 $this->assertArrayNotHasKey( $cookie, $cookie_jar ); 317 317 } else { 318 $this->assertInstanceOf( ' WpOrg\Requests\Cookie', $cookie_jar[ $cookie ] );318 $this->assertInstanceOf( 'Requests_Cookie', $cookie_jar[ $cookie ] ); 319 319 } 320 320 } -
trunk/tests/phpunit/tests/rest-api/rest-widgets-controller.php
r52244 r52328 417 417 418 418 return array( 419 'headers' => new WpOrg\Requests\Utility\CaseInsensitiveDictionary( $single_value_headers ),419 'headers' => new Requests_Utility_CaseInsensitiveDictionary( $single_value_headers ), 420 420 'body' => file_get_contents( DIR_TESTDATA . '/feed/wordpress-org-news.xml' ), 421 421 'response' => array( -
trunk/tests/phpunit/tests/widgets/wpWidgetRss.php
r52244 r52328 107 107 108 108 return array( 109 'headers' => new WpOrg\Requests\Utility\CaseInsensitiveDictionary( $single_value_headers ),109 'headers' => new Requests_Utility_CaseInsensitiveDictionary( $single_value_headers ), 110 110 'body' => file_get_contents( DIR_TESTDATA . '/feed/wordpress-org-news.xml' ), 111 111 'response' => array(
Note: See TracChangeset
for help on using the changeset viewer.