mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-09-10 10:26:35 +00:00
Replace abstract class CurlCookieConst and array_key_exists() with isset()
This commit is contained in:
+37
-43
@@ -2,52 +2,44 @@
|
||||
|
||||
namespace Curl;
|
||||
|
||||
abstract class CurlCookieConst
|
||||
{
|
||||
private static $RFC2616 = array();
|
||||
private static $RFC6265 = array();
|
||||
|
||||
public static function Init() {
|
||||
self::$RFC2616 = array_fill_keys(array(
|
||||
// RFC2616: "any CHAR except CTLs or separators".
|
||||
'!', '#', '$', '%', '&', "'", '*', '+', '-', '.', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A',
|
||||
'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
|
||||
'W', 'X', 'Y', 'Z', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
|
||||
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '|', '~',
|
||||
), true);
|
||||
|
||||
self::$RFC6265 = array_fill_keys(array(
|
||||
// RFC6265: "US-ASCII characters excluding CTLs, whitespace DQUOTE, comma, semicolon, and backslash".
|
||||
// %x21
|
||||
'!',
|
||||
// %x23-2B
|
||||
'#', '$', '%', '&', "'", '(', ')', '*', '+',
|
||||
// %x2D-3A
|
||||
'-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':',
|
||||
// %x3C-5B
|
||||
'<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
|
||||
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[',
|
||||
// %x5D-7E
|
||||
']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
|
||||
'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~',
|
||||
), true);
|
||||
}
|
||||
|
||||
public static function RFC2616() {
|
||||
return self::$RFC2616;
|
||||
}
|
||||
|
||||
public static function RFC6265() {
|
||||
return self::$RFC6265;
|
||||
}
|
||||
}
|
||||
|
||||
CurlCookieConst::Init();
|
||||
|
||||
class Curl
|
||||
{
|
||||
const VERSION = '4.8.2';
|
||||
const DEFAULT_TIMEOUT = 30;
|
||||
const RFC2616 = array(
|
||||
// RFC2616: "any CHAR except CTLs or separators".
|
||||
// CHAR = <any US-ASCII character (octets 0 - 127)>
|
||||
// CTL = <any US-ASCII control character
|
||||
// (octets 0 - 31) and DEL (127)>
|
||||
// separators = "(" | ")" | "<" | ">" | "@"
|
||||
// | "," | ";" | ":" | "\" | <">
|
||||
// | "/" | "[" | "]" | "?" | "="
|
||||
// | "{" | "}" | SP | HT
|
||||
// SP = <US-ASCII SP, space (32)>
|
||||
// HT = <US-ASCII HT, horizontal-tab (9)>
|
||||
// <"> = <US-ASCII double-quote mark (34)>
|
||||
'!', '#', '$', '%', '&', "'", '*', '+', '-', '.', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
|
||||
'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
|
||||
'Y', 'Z', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
|
||||
'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '|', '~',
|
||||
);
|
||||
const RFC6265 = array(
|
||||
// RFC6265: "US-ASCII characters excluding CTLs, whitespace DQUOTE, comma, semicolon, and backslash".
|
||||
// %x21
|
||||
'!',
|
||||
// %x23-2B
|
||||
'#', '$', '%', '&', "'", '(', ')', '*', '+',
|
||||
// %x2D-3A
|
||||
'-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':',
|
||||
// %x3C-5B
|
||||
'<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
|
||||
'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[',
|
||||
// %x5D-7E
|
||||
']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
|
||||
's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~',
|
||||
);
|
||||
|
||||
|
||||
public $curl;
|
||||
public $id = null;
|
||||
@@ -110,6 +102,8 @@ class Curl
|
||||
$this->setOpt(CURLOPT_RETURNTRANSFER, true);
|
||||
$this->headers = new CaseInsensitiveArray();
|
||||
$this->setURL($base_url);
|
||||
$this->RFC2616 = array_fill_keys(self::RFC2616, true);
|
||||
$this->RFC6265 = array_fill_keys(self::RFC6265, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -587,7 +581,7 @@ class Curl
|
||||
{
|
||||
$name_chars = array();
|
||||
foreach (str_split($key) as $name_char) {
|
||||
if (!array_key_exists($name_char, CurlCookieConst::RFC2616())) {
|
||||
if (!isset($this->RFC2616[$name_char])) {
|
||||
$name_chars[] = rawurlencode($name_char);
|
||||
} else {
|
||||
$name_chars[] = $name_char;
|
||||
@@ -596,7 +590,7 @@ class Curl
|
||||
|
||||
$value_chars = array();
|
||||
foreach (str_split($value) as $value_char) {
|
||||
if (!array_key_exists($value_char, CurlCookieConst::RFC6265())) {
|
||||
if (!isset($this->RFC6265[$value_char])) {
|
||||
$value_chars[] = rawurlencode($value_char);
|
||||
} else {
|
||||
$value_chars[] = $value_char;
|
||||
|
||||
Reference in New Issue
Block a user