Skip to content

Commit 51eb1d4

Browse files
authored
Fix curl/sync_constants.php (#9391)
1 parent f743cb0 commit 51eb1d4

File tree

2 files changed

+76
-72
lines changed

2 files changed

+76
-72
lines changed

ext/curl/interface.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,6 @@ PHP_MINFO_FUNCTION(curl)
367367
}
368368
/* }}} */
369369

370-
#define REGISTER_CURL_CONSTANT(__c) REGISTER_LONG_CONSTANT(#__c, __c, CONST_CS | CONST_PERSISTENT)
371-
372370
/* {{{ PHP_MINIT_FUNCTION */
373371
PHP_MINIT_FUNCTION(curl)
374372
{

ext/curl/sync-constants.php

Lines changed: 76 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,87 @@
1010

1111
const CURL_DOC_FILE = 'https://curl.haxx.se/libcurl/c/symbols-in-versions.html';
1212

13-
const SOURCE_FILE = __DIR__ . '/interface.c';
13+
const SOURCE_FILE = __DIR__ . '/curl_arginfo.h';
1414

1515
const MIN_SUPPORTED_CURL_VERSION = '7.29.0';
1616

17-
const IGNORED_CONSTANTS = [
17+
const IGNORED_CURL_CONSTANTS = [
1818
'CURLOPT_PROGRESSDATA',
19-
'CURLOPT_XFERINFODATA'
19+
'CURLOPT_XFERINFODATA',
20+
];
21+
22+
const IGNORED_PHP_CONSTANTS = [
23+
'CURLOPT_BINARYTRANSFER',
24+
'CURLOPT_RETURNTRANSFER',
25+
'CURLOPT_SAFE_UPLOAD',
2026
];
2127

2228
const CONSTANTS_REGEX_PATTERN = '~^CURL(?:OPT|_VERSION)_[A-Z0-9_]+$~';
2329

30+
/**
31+
* A simple helper to create ASCII tables.
32+
* It assumes that the same number of columns is always given to add().
33+
*/
34+
class AsciiTable
35+
{
36+
/**
37+
* @var array
38+
*/
39+
private $values = [];
40+
41+
/**
42+
* @var array
43+
*/
44+
private $length = [];
45+
46+
/**
47+
* @var int
48+
*/
49+
private $padding = 4;
50+
51+
/**
52+
* @param string[] $values
53+
*
54+
* @return void
55+
*/
56+
public function add(string ...$values) : void
57+
{
58+
$this->values[] = $values;
59+
60+
foreach ($values as $key => $value) {
61+
$length = strlen($value);
62+
63+
if (isset($this->length[$key])) {
64+
$this->length[$key] = max($this->length[$key], $length);
65+
} else {
66+
$this->length[$key] = $length;
67+
}
68+
}
69+
}
70+
71+
/**
72+
* @return string
73+
*/
74+
public function __toString() : string
75+
{
76+
$result = '';
77+
78+
foreach ($this->values as $values) {
79+
foreach ($values as $key => $value) {
80+
if ($key !== 0) {
81+
$result .= str_repeat(' ', $this->padding);
82+
}
83+
84+
$result .= str_pad($value, $this->length[$key]);
85+
}
86+
87+
$result .= "\n";
88+
}
89+
90+
return $result;
91+
}
92+
}
93+
2494
$curlConstants = getCurlConstants();
2595
$sourceConstants = getSourceConstants();
2696

@@ -161,7 +231,7 @@ function getCurlConstants() : array
161231
$deprecated = $match[3] ?? null;
162232
$removed = $match[4] ?? null;
163233

164-
if (in_array($name, IGNORED_CONSTANTS, true) || !preg_match(CONSTANTS_REGEX_PATTERN, $name)) {
234+
if (in_array($name, IGNORED_CURL_CONSTANTS, true) || !preg_match(CONSTANTS_REGEX_PATTERN, $name)) {
165235
// not a wanted constant
166236
continue;
167237
}
@@ -187,7 +257,7 @@ function getSourceConstants() : array
187257
{
188258
$source = file_get_contents(SOURCE_FILE);
189259

190-
preg_match_all('/REGISTER_CURL_CONSTANT\(([A-Za-z0-9_]+)\)/', $source, $matches);
260+
preg_match_all('/REGISTER_LONG_CONSTANT\(\"\w+\", (\w+), .+\)/', $source, $matches);
191261

192262
$constants = [];
193263

@@ -196,7 +266,7 @@ function getSourceConstants() : array
196266
continue;
197267
}
198268

199-
if (!preg_match(CONSTANTS_REGEX_PATTERN, $name)) {
269+
if (in_array($name, IGNORED_PHP_CONSTANTS, true) || !preg_match(CONSTANTS_REGEX_PATTERN, $name)) {
200270
// not a wanted constant
201271
continue;
202272
}
@@ -254,67 +324,3 @@ function getHexVersion(string $version) : string
254324

255325
return $hex;
256326
}
257-
258-
/**
259-
* A simple helper to create ASCII tables.
260-
* It assumes that the same number of columns is always given to add().
261-
*/
262-
class AsciiTable
263-
{
264-
/**
265-
* @var array
266-
*/
267-
private $values = [];
268-
269-
/**
270-
* @var array
271-
*/
272-
private $length = [];
273-
274-
/**
275-
* @var int
276-
*/
277-
private $padding = 4;
278-
279-
/**
280-
* @param string[] $values
281-
*
282-
* @return void
283-
*/
284-
public function add(string ...$values) : void
285-
{
286-
$this->values[] = $values;
287-
288-
foreach ($values as $key => $value) {
289-
$length = strlen($value);
290-
291-
if (isset($this->length[$key])) {
292-
$this->length[$key] = max($this->length[$key], $length);
293-
} else {
294-
$this->length[$key] = $length;
295-
}
296-
}
297-
}
298-
299-
/**
300-
* @return string
301-
*/
302-
public function __toString() : string
303-
{
304-
$result = '';
305-
306-
foreach ($this->values as $values) {
307-
foreach ($values as $key => $value) {
308-
if ($key !== 0) {
309-
$result .= str_repeat(' ', $this->padding);
310-
}
311-
312-
$result .= str_pad($value, $this->length[$key]);
313-
}
314-
315-
$result .= "\n";
316-
}
317-
318-
return $result;
319-
}
320-
}

0 commit comments

Comments
 (0)