Skip to content

Move routing, hydration, and other internal code to Internal namespace #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/Gatherer/Hydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function gather(
Schema ...$schemaClasses,
): \ApiClients\Tools\OpenApiClientGenerator\Representation\Hydrator {
return new \ApiClients\Tools\OpenApiClientGenerator\Representation\Hydrator(
ClassString::factory($baseNamespace, 'Hydrator\\' . $className),
ClassString::factory($baseNamespace, 'Internal\\Hydrator\\' . $className),
str_replace(['\\', '/'], ['/', $nameSpaceSeperator], lcfirst($className)),
$schemaClasses,
);
Expand Down
4 changes: 2 additions & 2 deletions src/Gatherer/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ public static function gather(
$group = strlen(trim(trim(Utils::dirname($className), '\\'), '.')) > 0 ? trim(str_replace('\\', '', Utils::dirname($className)), '\\') : null;

return new \ApiClients\Tools\OpenApiClientGenerator\Representation\Operation(
ClassString::factory($baseNamespace, 'Operation\\' . Utils::fixKeyword($className)),
ClassString::factory($baseNamespace, 'Internal\\Operation\\' . Utils::fixKeyword($className)),
ClassString::factory($baseNamespace, $classNameSanitized),
ClassString::factory($baseNamespace, 'Operator\\' . Utils::fixKeyword($className)),
ClassString::factory($baseNamespace, 'Internal\\Operator\\' . Utils::fixKeyword($className)),
lcfirst(
str_replace(
['\\'],
Expand Down
2 changes: 1 addition & 1 deletion src/Gatherer/WebHookHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static function gather(

return Hydrator::gather(
$baseNamespace,
'WebHook\\' . Utils::className($event),
'Internal\\WebHook\\' . Utils::className($event),
'🪝',
...$schemaClasses,
);
Expand Down
5 changes: 1 addition & 4 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,9 @@ public function generate(string $namespace, string $namespaceTest, string $confi
}
})([
ltrim($namespace, '\\') . 'Error' => 'ErrorSchemas',
ltrim($namespace, '\\') . 'Hydrator' => null,
ltrim($namespace, '\\') . 'Internal' => null,
ltrim($namespace, '\\') . 'Operation' => null,
ltrim($namespace, '\\') . 'Operator' => null,
ltrim($namespace, '\\') . 'Schema' => null,
ltrim($namespace, '\\') . 'WebHook' => null,
ltrim($namespace, '\\') . 'Router' => null,
'League\OpenAPIValidation' => null,
'React\Http' => null,
'ApiClients\Contracts' => null,
Expand Down
14 changes: 7 additions & 7 deletions src/Generator/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static function generate(Configuration $configuration, string $pathPrefix
}

$class->addStmt(
$factory->property('routers')->setType('Routers')->makeReadonly()->makePrivate(),
$factory->property('routers')->setType('Internal\\Routers')->makeReadonly()->makePrivate(),
)->addStmt(
$factory->method('__construct')->makePublic()->addParam(
(new Param('authentication'))->setType('\\' . AuthenticationInterface::class),
Expand Down Expand Up @@ -143,7 +143,7 @@ public static function generate(Configuration $configuration, string $pathPrefix
new Node\Expr\Assign(
new Node\Expr\Variable('hydrators'),
new Node\Expr\New_(
new Node\Name('Hydrators'),
new Node\Name('Internal\\Hydrators'),
[],
),
),
Expand All @@ -159,7 +159,7 @@ public static function generate(Configuration $configuration, string $pathPrefix
[
new Arg(
new Node\Expr\New_(
new Node\Name('Operators'),
new Node\Name('Internal\\Operators'),
[
new Arg(
new Node\Expr\Variable('browser'),
Expand Down Expand Up @@ -239,7 +239,7 @@ public static function generate(Configuration $configuration, string $pathPrefix
'routers',
),
new Node\Expr\New_(
new Node\Name('Routers'),
new Node\Name('Internal\\Routers'),
[
new Arg(
new Node\Expr\Variable('browser'),
Expand Down Expand Up @@ -374,7 +374,7 @@ public static function generate(Configuration $configuration, string $pathPrefix
),
);
$chunkCountClasses[] = $cc = new ChunkCount(
'Router\\' . (new Convert($method))->toPascal() . '\\' . (new Convert(NumberToWords::transformNumber('en', $chunkCount)))->toPascal(),
'Internal\\Router\\' . (new Convert($method))->toPascal() . '\\' . (new Convert(NumberToWords::transformNumber('en', $chunkCount)))->toPascal(),
$returnTypes,
$docBlockReturnTypes,
self::traverseOperations(
Expand Down Expand Up @@ -1029,7 +1029,7 @@ private static function createRouter(string $pathPrefix, string $namespace, Rout
)->addParam(
(new PrivatePromotedPropertyAsParam('responseSchemaValidator'))->setType('\League\OpenAPIValidation\Schema\SchemaValidator'),
)->addParam(
(new PrivatePromotedPropertyAsParam('hydrators'))->setType('\\' . $namespace . 'Hydrators'),
(new PrivatePromotedPropertyAsParam('hydrators'))->setType('Internal\\Hydrators'),
)->addParam(
(new PrivatePromotedPropertyAsParam('browser'))->setType('\\' . Browser::class),
)->addParam(
Expand Down Expand Up @@ -1071,7 +1071,7 @@ private static function createRouterChunkSize(string $pathPrefix, string $namesp

$class = $factory->class(Utils::basename($namespace . $chunkCount->className))->makeFinal()->addStmt(
$factory->method('__construct')->makePublic()->addParam(
(new PrivatePromotedPropertyAsParam('routers'))->setType('\\' . $namespace . 'Routers'),
(new PrivatePromotedPropertyAsParam('routers'))->setType('\\' . $namespace . 'Internal\\Routers'),
),
);

Expand Down
2 changes: 1 addition & 1 deletion src/Generator/Client/Routers.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function createClassName(
string|null $group,
string $name,
): Router {
$className = rtrim('Router\\' . (new Convert($method))->toPascal() . ($group === null ? '' : '\\' . (new Convert($group))->toPascal()), '\\');
$className = rtrim('Internal\\Router\\' . (new Convert($method))->toPascal() . ($group === null ? '' : '\\' . (new Convert($group))->toPascal()), '\\');

return new Router(
$className,
Expand Down
4 changes: 2 additions & 2 deletions src/Generator/Hydrators.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static function generate(string $pathPrefix, string $namespace, Hydrator
{
$knownScehmas = [];
$factory = new BuilderFactory();
$stmt = $factory->namespace(trim($namespace, '\\'));
$stmt = $factory->namespace(trim($namespace, '\\') . '\\Internal');

$class = $factory->class('Hydrators')->makeFinal()->implement('\\' . ObjectMapper::class);

Expand Down Expand Up @@ -296,6 +296,6 @@ public static function generate(string $pathPrefix, string $namespace, Hydrator
);
}

yield new File($pathPrefix, 'Hydrators', $stmt->addStmt($class)->getNode());
yield new File($pathPrefix, 'Internal\\Hydrators', $stmt->addStmt($class)->getNode());
}
}
4 changes: 2 additions & 2 deletions src/Generator/Operations.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function generate(Configuration $configuration, string $pathPrefix

$class->addStmt(
$factory->method('__construct')->makePublic()->addParam(
(new PrivatePromotedPropertyAsParam('operators'))->setType('\\' . $configuration->namespace->source . '\Operators'),
(new PrivatePromotedPropertyAsParam('operators'))->setType('Internal\\Operators'),
),
);

Expand Down Expand Up @@ -110,7 +110,7 @@ private static function generateOperationsGroup(string $pathPrefix, Configuratio

$class = $factory->class(Utils::basename($className))->makeFinal()->addStmt(
$factory->method('__construct')->makePublic()->addParam(
(new PrivatePromotedPropertyAsParam('operators'))->setType('\\' . $namespace->source . '\Operators'),
(new PrivatePromotedPropertyAsParam('operators'))->setType('Internal\Operators'),
),
);

Expand Down
6 changes: 3 additions & 3 deletions src/Generator/Operators.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class Operators
public static function generate(Configuration $configuration, string $pathPrefix, array $operations, array $operationHydratorMap): iterable
{
$factory = new BuilderFactory();
$stmt = $factory->namespace(trim($configuration->namespace->source, '\\'));
$stmt = $factory->namespace(trim($configuration->namespace->source, '\\') . '\\Internal');

$class = $factory->class('Operators')->makeFinal()->addStmt(
$factory->method('__construct')->makePublic()->addParam(
Expand All @@ -41,7 +41,7 @@ public static function generate(Configuration $configuration, string $pathPrefix
)->addParam(
(new PrivatePromotedPropertyAsParam('responseSchemaValidator'))->setType('\League\OpenAPIValidation\Schema\SchemaValidator')->makeReadonly(),
)->addParam(
(new PrivatePromotedPropertyAsParam('hydrators'))->setType('Hydrators')->makeReadonly(),
(new PrivatePromotedPropertyAsParam('hydrators'))->setType('Internal\\Hydrators')->makeReadonly(),
),
);

Expand Down Expand Up @@ -111,6 +111,6 @@ public static function generate(Configuration $configuration, string $pathPrefix
]);
}

yield new File($pathPrefix, 'Operators', $stmt->addStmt($class)->getNode());
yield new File($pathPrefix, 'Internal\\Operators', $stmt->addStmt($class)->getNode());
}
}
6 changes: 3 additions & 3 deletions src/Generator/Routers.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class Routers
public static function generate(Configuration $configuration, string $pathPrefix, ClientRouters $routers): iterable
{
$factory = new BuilderFactory();
$stmt = $factory->namespace(trim($configuration->namespace->source, '\\'));
$stmt = $factory->namespace(trim($configuration->namespace->source, '\\') . '\\Internal');

$class = $factory->class('Routers')->makeFinal()->addStmt(
$factory->method('__construct')->makePublic()->addParam(
Expand All @@ -34,7 +34,7 @@ public static function generate(Configuration $configuration, string $pathPrefix
)->addParam(
(new PrivatePromotedPropertyAsParam('responseSchemaValidator'))->setType('\League\OpenAPIValidation\Schema\SchemaValidator')->makeReadonly(),
)->addParam(
(new PrivatePromotedPropertyAsParam('hydrators'))->setType('Hydrators')->makeReadonly(),
(new PrivatePromotedPropertyAsParam('hydrators'))->setType('Internal\\Hydrators')->makeReadonly(),
),
);

Expand Down Expand Up @@ -132,6 +132,6 @@ public static function generate(Configuration $configuration, string $pathPrefix
]);
}

yield new File($pathPrefix, 'Routers', $stmt->addStmt($class)->getNode());
yield new File($pathPrefix, 'Internal\\Routers', $stmt->addStmt($class)->getNode());
}
}
4 changes: 2 additions & 2 deletions src/Generator/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public static function generate(string $pathPrefix, Representation\Schema $schem
$schemaClasses = [...self::getUnionTypeSchemas($property->type)];

if (count($schemaClasses) > 0) {
$castToUnionToType = ClassString::factory($schema->className->baseNamespaces, Utils::className('Attribute\\CastUnionToType\\' . $schema->className->relative . '\\' . $property->name));
$castToUnionToType = ClassString::factory($schema->className->baseNamespaces, Utils::className('Internal\\Attribute\\CastUnionToType\\' . $schema->className->relative . '\\' . $property->name));

yield from CastUnionToType::generate($pathPrefix, $castToUnionToType, ...$schemaClasses);

Expand All @@ -164,7 +164,7 @@ public static function generate(string $pathPrefix, Representation\Schema $schem
$iterableType = self::buildUnionType($iterableType);

if (count($schemaClasses) > 0) {
$castToUnionToType = ClassString::factory($schema->className->baseNamespaces, Utils::className('Attribute\\CastUnionToType\\' . $schema->className->relative . '\\' . $property->name));
$castToUnionToType = ClassString::factory($schema->className->baseNamespaces, Utils::className('Internal\\Attribute\\CastUnionToType\\' . $schema->className->relative . '\\' . $property->name));

yield from CastUnionToType::generate($pathPrefix, $castToUnionToType, ...$schemaClasses);

Expand Down
6 changes: 3 additions & 3 deletions src/Generator/WebHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public static function generate(
' */',
])));
$class->addStmt($factory->property('requestSchemaValidator')->setType('\\' . SchemaValidator::class)->makeReadonly()->makePrivate());
$class->addStmt($factory->property('hydrator')->setType('Hydrator\\WebHook' . $className)->makeReadonly()->makePrivate());
$class->addStmt($factory->property('hydrator')->setType('Internal\\Hydrator\\WebHook' . $className)->makeReadonly()->makePrivate());

$constructor = $factory->method('__construct')->makePublic()->addParam(
(new Param('requestSchemaValidator'))->setType('\\' . SchemaValidator::class),
)->addParam(
(new Param('hydrator'))->setType('Hydrator\\WebHook' . $className),
(new Param('hydrator'))->setType('Internal\\Hydrator\\WebHook' . $className),
)->addStmt(
new Node\Expr\Assign(
new Node\Expr\PropertyFetch(
Expand Down Expand Up @@ -187,6 +187,6 @@ public static function generate(
$method->addStmts($tmts);
$class->addStmt($method);

yield new File($pathPrefix, 'WebHook\\' . $className, $stmt->addStmt($class)->getNode());
yield new File($pathPrefix, 'Internal\\WebHook\\' . $className, $stmt->addStmt($class)->getNode());
}
}
4 changes: 2 additions & 2 deletions src/Generator/WebHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public static function generate(string $pathPrefix, string $namespace, array $we

$class = $factory->class('WebHooks')->makeFinal()->implement('\\' . WebHooksInterface::class);
$class->addStmt($factory->property('requestSchemaValidator')->setType('\\' . SchemaValidator::class)->makeReadonly()->makePrivate());
$class->addStmt($factory->property('hydrator')->setType('Hydrators')->makeReadonly()->makePrivate());
$class->addStmt($factory->property('hydrator')->setType('Internal\\Hydrators')->makeReadonly()->makePrivate());

$constructor = $factory->method('__construct')->makePublic()->addParams([
(new Param('requestSchemaValidator'))->setType('\\' . SchemaValidator::class),
(new Param('hydrator'))->setType('Hydrators'),
(new Param('hydrator'))->setType('Internal\\Hydrators'),
])->addStmts([
new Node\Expr\Assign(
new Node\Expr\PropertyFetch(
Expand Down
Loading