From aed9fff159e1078fbe47187eb0df55c49bf90bd6 Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Mon, 30 Jan 2023 17:55:22 +0100 Subject: [PATCH 1/3] Hydrator namespace fix --- src/Generator/WebHooks.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Generator/WebHooks.php b/src/Generator/WebHooks.php index e67d7af..2e3b303 100644 --- a/src/Generator/WebHooks.php +++ b/src/Generator/WebHooks.php @@ -53,7 +53,7 @@ public static function generate(string $namespace, string $baseNamespace, array Class_::MODIFIER_PUBLIC ) )->addStmt( - $factory->property('hydrator')->setType('\\' . $namespace . 'OptimizedHydratorMapper')->makeReadonly()->makePrivate() + $factory->property('hydrator')->setType('\\' . $baseNamespace . 'OptimizedHydratorMapper')->makeReadonly()->makePrivate() )->addStmt( $factory->method('__construct')->makePublic()->addStmt( new Node\Expr\Assign( @@ -62,7 +62,7 @@ public static function generate(string $namespace, string $baseNamespace, array 'hydrator' ), new Node\Expr\New_( - new Node\Name('\\' . $namespace . 'OptimizedHydratorMapper'), + new Node\Name('\\' . $baseNamespace . 'OptimizedHydratorMapper'), [ ] ), From a4c2cd05d00bfcd31d5f8455a6933fe501d93391 Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Mon, 30 Jan 2023 18:00:35 +0100 Subject: [PATCH 2/3] Hydrate object call on client --- src/Generator/Client.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Generator/Client.php b/src/Generator/Client.php index ae4775d..214e776 100644 --- a/src/Generator/Client.php +++ b/src/Generator/Client.php @@ -314,6 +314,26 @@ public static function generate(string $namespace, array $clients, SchemaRegistr )) ); + $class->addStmt( + $factory->method('hydrateObject')->makePublic()->setReturnType('object')->addParam( + (new Param('className'))->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\Variable('className')), + new Node\Arg(new Node\Expr\Variable('data')), + ] + ) + )) + ); + yield new File($namespace . '\\' . 'Client', $stmt->addStmt($class)->getNode()); } } From 676230ba8c4933a563c6c177139d93cfa6111da0 Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Mon, 30 Jan 2023 18:04:59 +0100 Subject: [PATCH 3/3] Throw exception when we can't match call --- src/Generator/Client.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Generator/Client.php b/src/Generator/Client.php index 214e776..055e89c 100644 --- a/src/Generator/Client.php +++ b/src/Generator/Client.php @@ -311,7 +311,13 @@ public static function generate(string $namespace, array $clients, SchemaRegistr // yield new Node\Stmt\Echo_([new Node\Scalar\String_('/**' . @var_export($operationCall, true) . '*/')]); } })($operationCalls)) - )) + ))->addStmt( + new Node\Stmt\Throw_( + new Node\Expr\New_( + new Node\Name('\InvalidArgumentException') + ) + ) + ) ); $class->addStmt(