|
2 | 2 |
|
3 | 3 | namespace ApiClients\Tools\OpenApiClientGenerator\Generator; |
4 | 4 |
|
| 5 | +use ApiClients\Contracts\HTTP\Headers\AuthenticationInterface; |
5 | 6 | use ApiClients\Contracts\OpenAPI\WebHookInterface; |
6 | 7 | use ApiClients\Tools\OpenApiClientGenerator\File; |
7 | 8 | use cebe\openapi\spec\Operation as OpenAPiOperation; |
|
14 | 15 | use PhpParser\Node\Stmt\Class_; |
15 | 16 | use Psr\Http\Message\RequestInterface; |
16 | 17 | use Psr\Http\Message\ServerRequestInterface; |
| 18 | +use React\Http\Browser; |
17 | 19 | use RingCentral\Psr7\Request; |
18 | 20 |
|
19 | 21 | final class WebHooks |
@@ -50,6 +52,22 @@ public static function generate(string $namespace, string $baseNamespace, array |
50 | 52 | ], |
51 | 53 | Class_::MODIFIER_PUBLIC |
52 | 54 | ) |
| 55 | + )->addStmt( |
| 56 | + $factory->property('hydrator')->setType('\\' . $namespace . 'OptimizedHydratorMapper')->makeReadonly()->makePrivate() |
| 57 | + )->addStmt( |
| 58 | + $factory->method('__construct')->makePublic()->addStmt( |
| 59 | + new Node\Expr\Assign( |
| 60 | + new Node\Expr\PropertyFetch( |
| 61 | + new Node\Expr\Variable('this'), |
| 62 | + 'hydrator' |
| 63 | + ), |
| 64 | + new Node\Expr\New_( |
| 65 | + new Node\Name('\\' . $namespace . 'OptimizedHydratorMapper'), |
| 66 | + [ |
| 67 | + ] |
| 68 | + ), |
| 69 | + ) |
| 70 | + ) |
53 | 71 | )->addStmt( |
54 | 72 | $factory->method('resolve')->makePublic()->makeStatic()->setReturnType('\\' . WebHookInterface::class)->addParam( |
55 | 73 | (new Param('event'))->setType('string') |
@@ -99,6 +117,36 @@ public static function generate(string $namespace, string $baseNamespace, array |
99 | 117 | ) |
100 | 118 | ) |
101 | 119 | )) |
| 120 | + )->addStmt( |
| 121 | + $factory->method('hydrate')->makePublic()->setReturnType('object')->addParam( |
| 122 | + (new Param('event'))->setType('string') |
| 123 | + )->addParam( |
| 124 | + (new Param('data'))->setType('array') |
| 125 | + )->addStmt(new Node\Stmt\Return_( |
| 126 | + new Node\Expr\MethodCall( |
| 127 | + new Node\Expr\PropertyFetch( |
| 128 | + new Node\Expr\Variable('this'), |
| 129 | + 'hydrator' |
| 130 | + ), |
| 131 | + new Node\Name('hydrateObject'), |
| 132 | + [ |
| 133 | + new Node\Arg(new Node\Expr\MethodCall( |
| 134 | + new Node\Expr\StaticCall( |
| 135 | + new Node\Name('self'), |
| 136 | + new Node\Name('resolve'), |
| 137 | + [ |
| 138 | + new Node\Arg(new Node\Expr\Variable('event')), |
| 139 | + ] |
| 140 | + ), |
| 141 | + new Node\Name('resolve'), |
| 142 | + [ |
| 143 | + new Node\Arg(new Node\Expr\Variable('data')), |
| 144 | + ] |
| 145 | + )), |
| 146 | + new Node\Arg(new Node\Expr\Variable('data')), |
| 147 | + ] |
| 148 | + ) |
| 149 | + )) |
102 | 150 | ); |
103 | 151 | yield new File($namespace . '\\' . 'WebHooks', $stmt->addStmt($class)->getNode()); |
104 | 152 | } |
|
0 commit comments