-
Notifications
You must be signed in to change notification settings - Fork 3
/
gen_stub.php-8.1.0.diff
262 lines (240 loc) · 10.7 KB
/
gen_stub.php-8.1.0.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
diff --git a/build/gen_stub.php b/build/gen_stub.php
index 5f74d26dbc..71265c12fa 100755
--- a/build/gen_stub.php
+++ b/build/gen_stub.php
@@ -733,10 +733,6 @@ class ArgInfo {
private function setTypes(?Type $type, ?Type $phpDocType): void
{
- if ($phpDocType !== null && Type::equals($type, $phpDocType)) {
- throw new Exception('PHPDoc param type "' . $phpDocType->__toString() . '" is unnecessary');
- }
-
$this->type = $type;
$this->phpDocType = $phpDocType;
}
@@ -793,7 +789,7 @@ class FunctionName implements FunctionOrMethodName {
}
public function getDeclarationName(): string {
- return $this->name->getLast();
+ return strtr($this->name->toString(), "\\", "_");
}
public function getDeclaration(): string {
@@ -910,10 +906,6 @@ class ReturnInfo {
private function setTypes(?Type $type, ?Type $phpDocType, bool $tentativeReturnType): void
{
- if ($phpDocType !== null && Type::equals($type, $phpDocType)) {
- throw new Exception('PHPDoc return type "' . $phpDocType->__toString() . '" is unnecessary');
- }
-
$this->type = $type;
$this->phpDocType = $phpDocType;
$this->tentativeReturnType = $tentativeReturnType;
@@ -1152,8 +1144,8 @@ class FuncInfo {
if ($namespace) {
// Render A\B as "A\\B" in C strings for namespaces
return sprintf(
- "\tZEND_NS_FE(\"%s\", %s, %s)\n",
- addslashes($namespace), $declarationName, $this->getArgInfoName());
+ "\tZEND_NS_RAW_FENTRY(\"%s\", \"%s\", ZEND_FN(%s), %s, 0)\n",
+ addslashes($namespace), substr((string)$this->name, strlen($namespace)+1), $declarationName, $this->getArgInfoName());
} else {
return sprintf("\tZEND_FE(%s, %s)\n", $declarationName, $this->getArgInfoName());
}
@@ -1398,6 +1390,8 @@ class PropertyInfo
public $defaultValueString;
/** @var bool */
public $isDocReadonly;
+ /** @var string|null */
+ public $link;
public function __construct(
PropertyName $name,
@@ -1406,7 +1400,8 @@ class PropertyInfo
?Type $phpDocType,
?Expr $defaultValue,
?string $defaultValueString,
- bool $isDocReadonly
+ bool $isDocReadonly,
+ ?string $link
) {
$this->name = $name;
$this->flags = $flags;
@@ -1415,6 +1410,7 @@ class PropertyInfo
$this->defaultValue = $defaultValue;
$this->defaultValueString = $defaultValueString;
$this->isDocReadonly = $isDocReadonly;
+ $this->link = $link;
}
public function discardInfoForOldPhpVersions(): void {
@@ -1540,9 +1536,13 @@ class PropertyInfo
$fieldsynopsisElement->appendChild(new DOMText("\n "));
$fieldsynopsisElement->appendChild($this->getFieldSynopsisType()->getTypeForDoc($doc));
- $className = str_replace("\\", "-", $this->name->class->toLowerString());
+ $className = str_replace(["\\", "_"], ["-", "-"], $this->name->class->toLowerString());
$varnameElement = $doc->createElement("varname", $this->name->property);
- $varnameElement->setAttribute("linkend", "$className.props." . strtolower($this->name->property));
+ if ($this->link) {
+ $varnameElement->setAttribute("linkend", $this->link);
+ } else {
+ $varnameElement->setAttribute("linkend", "$className.props." . strtolower(str_replace("_", "-", $this->name->property)));
+ }
$fieldsynopsisElement->appendChild(new DOMText("\n "));
$fieldsynopsisElement->appendChild($varnameElement);
@@ -1558,14 +1558,14 @@ class PropertyInfo
}
private function getFieldSynopsisType(): Type {
- if ($this->type) {
- return $this->type;
- }
-
if ($this->phpDocType) {
return $this->phpDocType;
}
+ if ($this->type) {
+ return $this->type;
+ }
+
throw new Exception("A property must have a type");
}
@@ -1608,7 +1608,7 @@ class EnumCaseInfo {
public function getDeclaration(): string {
$escapedName = addslashes($this->name);
if ($this->value === null) {
- $code = "\n\tzend_enum_add_case_cstr(class_entry, \"$escapedName\", NULL);\n";
+ $code = "\tzend_enum_add_case_cstr(class_entry, \"$escapedName\", NULL);\n";
} else {
$evaluator = new ConstExprEvaluator(function (Expr $expr) {
throw new Exception("Enum case $this->name has an unsupported value");
@@ -2005,11 +2005,11 @@ class ClassInfo {
}
public static function getClassSynopsisFilename(Name $name): string {
- return strtolower(implode('-', $name->parts));
+ return strtolower(str_replace("_", "-", implode('-', $name->parts)));
}
public static function getClassSynopsisReference(Name $name): string {
- return "class." . strtolower(implode('-', $name->parts));
+ return "class." . self::getClassSynopsisFilename($name);
}
/**
@@ -2019,10 +2019,6 @@ class ClassInfo {
*/
private function collectInheritedMembers(array &$parentsWithInheritedProperties, array &$parentsWithInheritedMethods, array $classMap): void
{
- if ($this->type !== "class") {
- return;
- }
-
foreach ($this->extends as $parent) {
$parentInfo = $classMap[$parent->toString()] ?? null;
if (!$parentInfo) {
@@ -2033,7 +2029,7 @@ class ClassInfo {
$parentsWithInheritedProperties[$parent->toString()] = $parent;
}
- if (!empty($parentInfo->funcInfos) && !isset($parentsWithInheritedMethods[$parent->toString()])) {
+ if (!isset($parentsWithInheritedMethods[$parent->toString()]) && $parentInfo->hasMethods()) {
$parentsWithInheritedMethods[$parent->toString()] = $parent;
}
@@ -2369,13 +2365,14 @@ function parseFunctionLike(
function parseProperty(
Name $class,
int $flags,
- Stmt\PropertyProperty $property,
+ Stmt\PropertyProperty|Node\Param $property,
?Node $type,
?DocComment $comment,
PrettyPrinterAbstract $prettyPrinter
): PropertyInfo {
$phpDocType = null;
$isDocReadonly = false;
+ $link = null;
if ($comment) {
$tags = parseDocComment($comment);
@@ -2384,6 +2381,8 @@ function parseProperty(
$phpDocType = $tag->getType();
} elseif ($tag->name === 'readonly') {
$isDocReadonly = true;
+ } elseif ($tag->name === 'link') {
+ $link = $tag->value;
}
}
}
@@ -2404,14 +2403,25 @@ function parseProperty(
}
}
+ $default = $property->default;
+ if ($property instanceof Node\Param) {
+ $name = $property->var->name;
+ if ($property->flags & Stmt\Class_::MODIFIER_READONLY) {
+ $default = null;
+ }
+ } else {
+ $name = $property->name;
+ }
+
return new PropertyInfo(
- new PropertyName($class, $property->name->__toString()),
+ new PropertyName($class, (string) $name),
$flags,
$propertyType,
$phpDocType ? Type::fromString($phpDocType) : null,
- $property->default,
- $property->default ? $prettyPrinter->prettyPrintExpr($property->default) : null,
- $isDocReadonly
+ $default,
+ $default ? $prettyPrinter->prettyPrintExpr($default) : null,
+ $isDocReadonly,
+ $link
);
}
@@ -2594,6 +2604,20 @@ function handleStatements(FileInfo $fileInfo, array $stmts, PrettyPrinterAbstrac
$classStmt,
$cond
);
+ if ($classStmt->name->toString() === "__construct") {
+ foreach ($classStmt->params as $param) {
+ if ($param->flags) {
+ $propertyInfos[] = parseProperty(
+ $className,
+ $param->flags,
+ $param,
+ $param->type,
+ $param->getDocComment(),
+ $prettyPrinter
+ );
+ }
+ }
+ }
} else if ($classStmt instanceof Stmt\EnumCase) {
$enumCaseInfos[] = new EnumCaseInfo(
$classStmt->name->toString(), $classStmt->expr);
@@ -2821,7 +2845,9 @@ function generateArgInfoCode(FileInfo $fileInfo, string $stubHash): string {
}
$generatedFunctionDeclarations[$key] = true;
- return $fileInfo->declarationPrefix . $funcInfo->getDeclaration();
+ if ($decl = $funcInfo->getDeclaration()) {
+ return $fileInfo->declarationPrefix . $decl;
+ }
}
);
@@ -2986,12 +3012,14 @@ function replaceClassSynopses(string $targetDirectory, array $classMap): array
$replacedXml = preg_replace(
[
"/REPLACED-ENTITY-([A-Za-z0-9._{}%-]+?;)/",
+ "/<phpdoc:(classref|exceptionref)\s+xmlns:phpdoc=\"([a-z0-9.:\/]+)\"\s+xmlns=\"([a-z0-9.:\/]+)\"\s+xml:id=\"([a-z0-9._-]+)\"\s*>/i",
"/<phpdoc:(classref|exceptionref)\s+xmlns:phpdoc=\"([a-z0-9.:\/]+)\"\s+xmlns=\"([a-z0-9.:\/]+)\"\s+xmlns:xi=\"([a-z0-9.:\/]+)\"\s+xml:id=\"([a-z0-9._-]+)\"\s*>/i",
"/<phpdoc:(classref|exceptionref)\s+xmlns:phpdoc=\"([a-z0-9.:\/]+)\"\s+xmlns=\"([a-z0-9.:\/]+)\"\s+xmlns:xlink=\"([a-z0-9.:\/]+)\"\s+xmlns:xi=\"([a-z0-9.:\/]+)\"\s+xml:id=\"([a-z0-9._-]+)\"\s*>/i",
"/<phpdoc:(classref|exceptionref)\s+xmlns=\"([a-z0-9.:\/]+)\"\s+xmlns:xlink=\"([a-z0-9.:\/]+)\"\s+xmlns:xi=\"([a-z0-9.:\/]+)\"\s+xmlns:phpdoc=\"([a-z0-9.:\/]+)\"\s+xml:id=\"([a-z0-9._-]+)\"\s*>/i",
],
[
"&$1",
+ "<phpdoc:$1 xml:id=\"$4\" xmlns:phpdoc=\"$2\" xmlns=\"$3\">",
"<phpdoc:$1 xml:id=\"$5\" xmlns:phpdoc=\"$2\" xmlns=\"$3\" xmlns:xi=\"$4\">",
"<phpdoc:$1 xml:id=\"$6\" xmlns:phpdoc=\"$2\" xmlns=\"$3\" xmlns:xlink=\"$4\" xmlns:xi=\"$5\">",
"<phpdoc:$1 xml:id=\"$6\" xmlns:phpdoc=\"$5\" xmlns=\"$2\" xmlns:xlink=\"$3\" xmlns:xi=\"$4\">",
@@ -3265,7 +3293,7 @@ function initPhpParser() {
}
$isInitialized = true;
- $version = "4.13.0";
+ $version = "4.13.2";
$phpParserDir = __DIR__ . "/PHP-Parser-$version";
if (!is_dir($phpParserDir)) {
installPhpParser($version, $phpParserDir);