Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/Generator/WebHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace ApiClients\Tools\OpenApiClientGenerator\Generator;

use ApiClients\Contracts\HTTP\Headers\AuthenticationInterface;
use ApiClients\Contracts\OpenAPI\WebHookInterface;
use ApiClients\Tools\OpenApiClientGenerator\File;
use cebe\openapi\spec\Operation as OpenAPiOperation;
Expand All @@ -14,6 +15,7 @@
use PhpParser\Node\Stmt\Class_;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ServerRequestInterface;
use React\Http\Browser;
use RingCentral\Psr7\Request;

final class WebHooks
Expand Down Expand Up @@ -50,6 +52,22 @@ public static function generate(string $namespace, string $baseNamespace, array
],
Class_::MODIFIER_PUBLIC
)
)->addStmt(
$factory->property('hydrator')->setType('\\' . $namespace . 'OptimizedHydratorMapper')->makeReadonly()->makePrivate()
)->addStmt(
$factory->method('__construct')->makePublic()->addStmt(
new Node\Expr\Assign(
new Node\Expr\PropertyFetch(
new Node\Expr\Variable('this'),
'hydrator'
),
new Node\Expr\New_(
new Node\Name('\\' . $namespace . 'OptimizedHydratorMapper'),
[
]
),
)
)
)->addStmt(
$factory->method('resolve')->makePublic()->makeStatic()->setReturnType('\\' . WebHookInterface::class)->addParam(
(new Param('event'))->setType('string')
Expand Down Expand Up @@ -99,6 +117,36 @@ public static function generate(string $namespace, string $baseNamespace, array
)
)
))
)->addStmt(
$factory->method('hydrate')->makePublic()->setReturnType('object')->addParam(
(new Param('event'))->setType('string')
)->addParam(
(new Param('data'))->setType('array')
)->addStmt(new Node\Stmt\Return_(
new Node\Expr\MethodCall(
new Node\Expr\PropertyFetch(
new Node\Expr\Variable('this'),
'hydrator'
),
new Node\Name('hydrateObject'),
[
new Node\Arg(new Node\Expr\MethodCall(
new Node\Expr\StaticCall(
new Node\Name('self'),
new Node\Name('resolve'),
[
new Node\Arg(new Node\Expr\Variable('event')),
]
),
new Node\Name('resolve'),
[
new Node\Arg(new Node\Expr\Variable('data')),
]
)),
new Node\Arg(new Node\Expr\Variable('data')),
]
)
))
);
yield new File($namespace . '\\' . 'WebHooks', $stmt->addStmt($class)->getNode());
}
Expand Down