fix #6: compatibility with 8.2
[awesomized/ext-ion] / gen_stub.php.diff
1 diff --git a/build/gen_stub.php b/build/gen_stub.php
2 index 486ff67949..71265c12fa 100755
3 --- a/build/gen_stub.php
4 +++ b/build/gen_stub.php
5 @@ -733,10 +733,6 @@ class ArgInfo {
6
7 private function setTypes(?Type $type, ?Type $phpDocType): void
8 {
9 - if ($phpDocType !== null && Type::equals($type, $phpDocType)) {
10 - throw new Exception('PHPDoc param type "' . $phpDocType->__toString() . '" is unnecessary');
11 - }
12 -
13 $this->type = $type;
14 $this->phpDocType = $phpDocType;
15 }
16 @@ -793,7 +789,7 @@ class FunctionName implements FunctionOrMethodName {
17 }
18
19 public function getDeclarationName(): string {
20 - return $this->name->getLast();
21 + return strtr($this->name->toString(), "\\", "_");
22 }
23
24 public function getDeclaration(): string {
25 @@ -910,10 +906,6 @@ class ReturnInfo {
26
27 private function setTypes(?Type $type, ?Type $phpDocType, bool $tentativeReturnType): void
28 {
29 - if ($phpDocType !== null && Type::equals($type, $phpDocType)) {
30 - throw new Exception('PHPDoc return type "' . $phpDocType->__toString() . '" is unnecessary');
31 - }
32 -
33 $this->type = $type;
34 $this->phpDocType = $phpDocType;
35 $this->tentativeReturnType = $tentativeReturnType;
36 @@ -1152,8 +1144,8 @@ class FuncInfo {
37 if ($namespace) {
38 // Render A\B as "A\\B" in C strings for namespaces
39 return sprintf(
40 - "\tZEND_NS_FE(\"%s\", %s, %s)\n",
41 - addslashes($namespace), $declarationName, $this->getArgInfoName());
42 + "\tZEND_NS_RAW_FENTRY(\"%s\", \"%s\", ZEND_FN(%s), %s, 0)\n",
43 + addslashes($namespace), substr((string)$this->name, strlen($namespace)+1), $declarationName, $this->getArgInfoName());
44 } else {
45 return sprintf("\tZEND_FE(%s, %s)\n", $declarationName, $this->getArgInfoName());
46 }
47 @@ -1616,7 +1608,7 @@ class EnumCaseInfo {
48 public function getDeclaration(): string {
49 $escapedName = addslashes($this->name);
50 if ($this->value === null) {
51 - $code = "\n\tzend_enum_add_case_cstr(class_entry, \"$escapedName\", NULL);\n";
52 + $code = "\tzend_enum_add_case_cstr(class_entry, \"$escapedName\", NULL);\n";
53 } else {
54 $evaluator = new ConstExprEvaluator(function (Expr $expr) {
55 throw new Exception("Enum case $this->name has an unsupported value");
56 @@ -2373,7 +2365,7 @@ function parseFunctionLike(
57 function parseProperty(
58 Name $class,
59 int $flags,
60 - Stmt\PropertyProperty $property,
61 + Stmt\PropertyProperty|Node\Param $property,
62 ?Node $type,
63 ?DocComment $comment,
64 PrettyPrinterAbstract $prettyPrinter
65 @@ -2411,13 +2403,23 @@ function parseProperty(
66 }
67 }
68
69 + $default = $property->default;
70 + if ($property instanceof Node\Param) {
71 + $name = $property->var->name;
72 + if ($property->flags & Stmt\Class_::MODIFIER_READONLY) {
73 + $default = null;
74 + }
75 + } else {
76 + $name = $property->name;
77 + }
78 +
79 return new PropertyInfo(
80 - new PropertyName($class, $property->name->__toString()),
81 + new PropertyName($class, (string) $name),
82 $flags,
83 $propertyType,
84 $phpDocType ? Type::fromString($phpDocType) : null,
85 - $property->default,
86 - $property->default ? $prettyPrinter->prettyPrintExpr($property->default) : null,
87 + $default,
88 + $default ? $prettyPrinter->prettyPrintExpr($default) : null,
89 $isDocReadonly,
90 $link
91 );
92 @@ -2602,6 +2604,20 @@ function handleStatements(FileInfo $fileInfo, array $stmts, PrettyPrinterAbstrac
93 $classStmt,
94 $cond
95 );
96 + if ($classStmt->name->toString() === "__construct") {
97 + foreach ($classStmt->params as $param) {
98 + if ($param->flags) {
99 + $propertyInfos[] = parseProperty(
100 + $className,
101 + $param->flags,
102 + $param,
103 + $param->type,
104 + $param->getDocComment(),
105 + $prettyPrinter
106 + );
107 + }
108 + }
109 + }
110 } else if ($classStmt instanceof Stmt\EnumCase) {
111 $enumCaseInfos[] = new EnumCaseInfo(
112 $classStmt->name->toString(), $classStmt->expr);
113 @@ -2829,7 +2845,9 @@ function generateArgInfoCode(FileInfo $fileInfo, string $stubHash): string {
114 }
115
116 $generatedFunctionDeclarations[$key] = true;
117 - return $fileInfo->declarationPrefix . $funcInfo->getDeclaration();
118 + if ($decl = $funcInfo->getDeclaration()) {
119 + return $fileInfo->declarationPrefix . $decl;
120 + }
121 }
122 );
123
124 @@ -3275,7 +3293,7 @@ function initPhpParser() {
125 }
126
127 $isInitialized = true;
128 - $version = "4.13.0";
129 + $version = "4.13.2";
130 $phpParserDir = __DIR__ . "/PHP-Parser-$version";
131 if (!is_dir($phpParserDir)) {
132 installPhpParser($version, $phpParserDir);