-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix curl/sync_constants.php #9391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,17 +10,87 @@ | |
|
||
const CURL_DOC_FILE = 'https://curl.haxx.se/libcurl/c/symbols-in-versions.html'; | ||
|
||
const SOURCE_FILE = __DIR__ . '/interface.c'; | ||
const SOURCE_FILE = __DIR__ . '/curl_arginfo.h'; | ||
|
||
const MIN_SUPPORTED_CURL_VERSION = '7.29.0'; | ||
|
||
const IGNORED_CONSTANTS = [ | ||
const IGNORED_CURL_CONSTANTS = [ | ||
'CURLOPT_PROGRESSDATA', | ||
'CURLOPT_XFERINFODATA' | ||
'CURLOPT_XFERINFODATA', | ||
]; | ||
|
||
const IGNORED_PHP_CONSTANTS = [ | ||
'CURLOPT_BINARYTRANSFER', | ||
'CURLOPT_RETURNTRANSFER', | ||
'CURLOPT_SAFE_UPLOAD', | ||
]; | ||
|
||
const CONSTANTS_REGEX_PATTERN = '~^CURL(?:OPT|_VERSION)_[A-Z0-9_]+$~'; | ||
|
||
/** | ||
* A simple helper to create ASCII tables. | ||
* It assumes that the same number of columns is always given to add(). | ||
*/ | ||
class AsciiTable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. had to move the declaration to the top, otherwise the class was not found on my system |
||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $values = []; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $length = []; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $padding = 4; | ||
|
||
/** | ||
* @param string[] $values | ||
* | ||
* @return void | ||
*/ | ||
public function add(string ...$values) : void | ||
{ | ||
$this->values[] = $values; | ||
|
||
foreach ($values as $key => $value) { | ||
$length = strlen($value); | ||
|
||
if (isset($this->length[$key])) { | ||
$this->length[$key] = max($this->length[$key], $length); | ||
} else { | ||
$this->length[$key] = $length; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function __toString() : string | ||
{ | ||
$result = ''; | ||
|
||
foreach ($this->values as $values) { | ||
foreach ($values as $key => $value) { | ||
if ($key !== 0) { | ||
$result .= str_repeat(' ', $this->padding); | ||
} | ||
|
||
$result .= str_pad($value, $this->length[$key]); | ||
} | ||
|
||
$result .= "\n"; | ||
} | ||
|
||
return $result; | ||
} | ||
} | ||
|
||
$curlConstants = getCurlConstants(); | ||
$sourceConstants = getSourceConstants(); | ||
|
||
|
@@ -161,7 +231,7 @@ function getCurlConstants() : array | |
$deprecated = $match[3] ?? null; | ||
$removed = $match[4] ?? null; | ||
|
||
if (in_array($name, IGNORED_CONSTANTS, true) || !preg_match(CONSTANTS_REGEX_PATTERN, $name)) { | ||
if (in_array($name, IGNORED_CURL_CONSTANTS, true) || !preg_match(CONSTANTS_REGEX_PATTERN, $name)) { | ||
// not a wanted constant | ||
continue; | ||
} | ||
|
@@ -187,7 +257,7 @@ function getSourceConstants() : array | |
{ | ||
$source = file_get_contents(SOURCE_FILE); | ||
|
||
preg_match_all('/REGISTER_CURL_CONSTANT\(([A-Za-z0-9_]+)\)/', $source, $matches); | ||
preg_match_all('/REGISTER_LONG_CONSTANT\(\"\w+\", (\w+), .+\)/', $source, $matches); | ||
|
||
$constants = []; | ||
|
||
|
@@ -196,7 +266,7 @@ function getSourceConstants() : array | |
continue; | ||
} | ||
|
||
if (!preg_match(CONSTANTS_REGEX_PATTERN, $name)) { | ||
if (in_array($name, IGNORED_PHP_CONSTANTS, true) || !preg_match(CONSTANTS_REGEX_PATTERN, $name)) { | ||
// not a wanted constant | ||
continue; | ||
} | ||
|
@@ -254,67 +324,3 @@ function getHexVersion(string $version) : string | |
|
||
return $hex; | ||
} | ||
|
||
/** | ||
* A simple helper to create ASCII tables. | ||
* It assumes that the same number of columns is always given to add(). | ||
*/ | ||
class AsciiTable | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $values = []; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $length = []; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $padding = 4; | ||
|
||
/** | ||
* @param string[] $values | ||
* | ||
* @return void | ||
*/ | ||
public function add(string ...$values) : void | ||
{ | ||
$this->values[] = $values; | ||
|
||
foreach ($values as $key => $value) { | ||
$length = strlen($value); | ||
|
||
if (isset($this->length[$key])) { | ||
$this->length[$key] = max($this->length[$key], $length); | ||
} else { | ||
$this->length[$key] = $length; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function __toString() : string | ||
{ | ||
$result = ''; | ||
|
||
foreach ($this->values as $values) { | ||
foreach ($values as $key => $value) { | ||
if ($key !== 0) { | ||
$result .= str_repeat(' ', $this->padding); | ||
} | ||
|
||
$result .= str_pad($value, $this->length[$key]); | ||
} | ||
|
||
$result .= "\n"; | ||
} | ||
|
||
return $result; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are custom PHP constants which should be ignored by the sync script