Skip to content

Commit

Permalink
Requests: set default options as a constant
Browse files Browse the repository at this point in the history
These values do not change during the request, so should be a constant and as the minimum PHP version is now PHP 5.6, we can use constant scalar expressions and constant arrays in constants.
  • Loading branch information
jrfnl committed Sep 17, 2021
1 parent b44f52c commit 6ab3e61
Showing 1 changed file with 35 additions and 21 deletions.
56 changes: 35 additions & 21 deletions src/Requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,38 @@ class Requests {
*/
const DEFAULT_CERT_PATH = __DIR__ . '/../certificates/cacert.pem';

/**
* Option defaults.
*
* @see \WpOrg\Requests\Requests::get_default_options()
* @see \WpOrg\Requests\Requests::request() for values returned by this method
*
* @since 2.0.0
*
* @var array
*/
const OPTION_DEFAULTS = array(
'timeout' => 10,
'connect_timeout' => 10,
'useragent' => 'php-requests/' . self::VERSION,
'protocol_version' => 1.1,
'redirected' => 0,
'redirects' => 10,
'follow_redirects' => true,
'blocking' => true,
'type' => self::GET,
'filename' => false,
'auth' => false,
'proxy' => false,
'cookies' => false,
'max_bytes' => false,
'idn' => true,
'hooks' => null,
'transport' => null,
'verify' => null,
'verifyname' => true,
);

/**
* Current version of Requests
*
Expand Down Expand Up @@ -493,27 +525,9 @@ public static function request_multiple($requests, $options = array()) {
* @return array Default option values
*/
protected static function get_default_options($multirequest = false) {
$defaults = array(
'timeout' => 10,
'connect_timeout' => 10,
'useragent' => 'php-requests/' . self::VERSION,
'protocol_version' => 1.1,
'redirected' => 0,
'redirects' => 10,
'follow_redirects' => true,
'blocking' => true,
'type' => self::GET,
'filename' => false,
'auth' => false,
'proxy' => false,
'cookies' => false,
'max_bytes' => false,
'idn' => true,
'hooks' => null,
'transport' => null,
'verify' => self::get_certificate_path(),
'verifyname' => true,
);
$defaults = static::OPTION_DEFAULTS;
$defaults['verify'] = self::get_certificate_path();

if ($multirequest !== false) {
$defaults['complete'] = null;
}
Expand Down

0 comments on commit 6ab3e61

Please sign in to comment.