Skip to content

Commit 2ce361f

Browse files
authored
Merge pull request #151 from php-api-clients/optimize-internal-call-routing
Optimize internal call routing
2 parents 6c87b89 + bda4d55 commit 2ce361f

File tree

6 files changed

+411
-244
lines changed

6 files changed

+411
-244
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"devizzent/cebe-php-openapi": "^1",
1818
"eventsauce/object-hydrator": "^1.2",
1919
"jawira/case-converter": "^3.5",
20+
"kwn/number-to-words": "^2.6",
2021
"league/openapi-psr7-validator": "^0.21",
2122
"nikic/php-parser": "^4.15",
2223
"nunomaduro/termwind": "^1.15",

composer.lock

Lines changed: 54 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Generator.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ public function generate(string $namespace, string $namespaceTest, string $confi
183183
'Schema' => null,
184184
'WebHook' => null,
185185
'Router' => null,
186-
'ChunkSize' => null,
187186
]));
188187
}
189188

@@ -425,8 +424,8 @@ private function oneClient(string $namespace, string $namespaceTest, string $con
425424
$this->configuration,
426425
$this->configuration->destination->source . DIRECTORY_SEPARATOR,
427426
$namespace,
427+
$paths,
428428
$operations,
429-
$routers,
430429
);
431430

432431
$webHooksHydrators = [];
@@ -658,8 +657,8 @@ private function subSplitClient(string $namespace, string $namespaceTest, string
658657
$this->configuration,
659658
$this->configuration->subSplit->subSplitsDestination . DIRECTORY_SEPARATOR . $this->splitPathPrefix($this->configuration->subSplit->rootPackage, '') . $this->configuration->destination->source,
660659
$namespace,
660+
$paths,
661661
$operations,
662-
$routers,
663662
);
664663

665664
$this->statusOutput->itemForStep('generating_webhooks', count($webHooks));

src/Generator/Client.php

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use ApiClients\Tools\OpenApiClientGenerator\Utils;
1616
use EventSauce\ObjectHydrator\ObjectMapper;
1717
use Jawira\CaseConverter\Convert;
18+
use NumberToWords\NumberToWords;
1819
use PhpParser\Builder\Method;
1920
use PhpParser\Builder\Param;
2021
use PhpParser\BuilderFactory;
@@ -353,30 +354,14 @@ public static function generate(Configuration $configuration, string $pathPrefix
353354
}
354355
}
355356

356-
// new Node\Stmt\Switch_(
357-
// new Node\Expr\Variable('method'),
358-
// iterator_to_array((function (array $sortedOperations) use ($factory): iterable {
359-
// foreach ($sortedOperations as $method => $operation) {
360-
// yield new Node\Stmt\Case_(
361-
// new Node\Scalar\String_($method),
362-
// [
363-
// ...self::traverseOperations($operation['operations'], $operation['paths'], 0),
364-
// new Node\Stmt\Break_(),
365-
// ],
366-
// );
367-
// }
368-
// })($sortedOperations))
369-
// )
370-
371-
372357
if ($configuration->entryPoints->call) {
373358
$chunkCountClasses = [];
374359
$operationsIfs = [];
375360
foreach ($sortedOperations as $method => $ops) {
376361
$opsTmts = [];
377362
foreach ($ops as $chunkCount => $moar) {
378363
$chunkCountClasses[] = $cc = new ChunkCount(
379-
'ChunkSize\\' . (new Convert($method))->toPascal() . '\\' . (new Convert('cc' . $chunkCount))->toPascal(),
364+
'Router\\' . (new Convert($method))->toPascal() . '\\' . (new Convert(NumberToWords::transformNumber('en', $chunkCount)))->toPascal(),
380365
self::traverseOperations($namespace, $moar['operations'], $moar['paths'], 0, $routers),
381366
);
382367

@@ -734,7 +719,7 @@ public static function generate(Configuration $configuration, string $pathPrefix
734719
}
735720

736721
foreach ($chunkCountClasses as $chunkCountClass) {
737-
yield from self::createChunkCount(
722+
yield from self::createRouterChunkSize(
738723
$pathPrefix,
739724
$namespace,
740725
$chunkCountClass,
@@ -1284,7 +1269,7 @@ private static function createRouter(string $pathPrefix, string $namespace, Rout
12841269
*
12851270
* @return iterable<File>
12861271
*/
1287-
private static function createChunkCount(string $pathPrefix, string $namespace, ChunkCount $chunkCount, Method $constructor, array $properties): iterable
1272+
private static function createRouterChunkSize(string $pathPrefix, string $namespace, ChunkCount $chunkCount, Method $constructor, array $properties): iterable
12881273
{
12891274
$factory = new BuilderFactory();
12901275
$stmt = $factory->namespace(trim(Utils::dirname($namespace . $chunkCount->className), '\\'));

0 commit comments

Comments
 (0)