Skip to content

Commit b085cf3

Browse files
authored
Merge pull request #201 from php-api-clients/more-routing-hydrating-to-internal-namespace
Move routing, hydration, and other internal code to Internal namespace
2 parents 705fb76 + d92c88c commit b085cf3

File tree

89 files changed

+527
-737
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+527
-737
lines changed

src/Gatherer/Hydrator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static function gather(
2020
Schema ...$schemaClasses,
2121
): \ApiClients\Tools\OpenApiClientGenerator\Representation\Hydrator {
2222
return new \ApiClients\Tools\OpenApiClientGenerator\Representation\Hydrator(
23-
ClassString::factory($baseNamespace, 'Hydrator\\' . $className),
23+
ClassString::factory($baseNamespace, 'Internal\\Hydrator\\' . $className),
2424
str_replace(['\\', '/'], ['/', $nameSpaceSeperator], lcfirst($className)),
2525
$schemaClasses,
2626
);

src/Gatherer/Operation.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ public static function gather(
153153
$group = strlen(trim(trim(Utils::dirname($className), '\\'), '.')) > 0 ? trim(str_replace('\\', '', Utils::dirname($className)), '\\') : null;
154154

155155
return new \ApiClients\Tools\OpenApiClientGenerator\Representation\Operation(
156-
ClassString::factory($baseNamespace, 'Operation\\' . Utils::fixKeyword($className)),
156+
ClassString::factory($baseNamespace, 'Internal\\Operation\\' . Utils::fixKeyword($className)),
157157
ClassString::factory($baseNamespace, $classNameSanitized),
158-
ClassString::factory($baseNamespace, 'Operator\\' . Utils::fixKeyword($className)),
158+
ClassString::factory($baseNamespace, 'Internal\\Operator\\' . Utils::fixKeyword($className)),
159159
lcfirst(
160160
str_replace(
161161
['\\'],

src/Gatherer/WebHookHydrator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static function gather(
2626

2727
return Hydrator::gather(
2828
$baseNamespace,
29-
'WebHook\\' . Utils::className($event),
29+
'Internal\\WebHook\\' . Utils::className($event),
3030
'🪝',
3131
...$schemaClasses,
3232
);

src/Generator.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,9 @@ public function generate(string $namespace, string $namespaceTest, string $confi
210210
}
211211
})([
212212
ltrim($namespace, '\\') . 'Error' => 'ErrorSchemas',
213-
ltrim($namespace, '\\') . 'Hydrator' => null,
213+
ltrim($namespace, '\\') . 'Internal' => null,
214214
ltrim($namespace, '\\') . 'Operation' => null,
215-
ltrim($namespace, '\\') . 'Operator' => null,
216215
ltrim($namespace, '\\') . 'Schema' => null,
217-
ltrim($namespace, '\\') . 'WebHook' => null,
218-
ltrim($namespace, '\\') . 'Router' => null,
219216
'League\OpenAPIValidation' => null,
220217
'React\Http' => null,
221218
'ApiClients\Contracts' => null,

src/Generator/Client.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static function generate(Configuration $configuration, string $pathPrefix
8080
}
8181

8282
$class->addStmt(
83-
$factory->property('routers')->setType('Routers')->makeReadonly()->makePrivate(),
83+
$factory->property('routers')->setType('Internal\\Routers')->makeReadonly()->makePrivate(),
8484
)->addStmt(
8585
$factory->method('__construct')->makePublic()->addParam(
8686
(new Param('authentication'))->setType('\\' . AuthenticationInterface::class),
@@ -143,7 +143,7 @@ public static function generate(Configuration $configuration, string $pathPrefix
143143
new Node\Expr\Assign(
144144
new Node\Expr\Variable('hydrators'),
145145
new Node\Expr\New_(
146-
new Node\Name('Hydrators'),
146+
new Node\Name('Internal\\Hydrators'),
147147
[],
148148
),
149149
),
@@ -159,7 +159,7 @@ public static function generate(Configuration $configuration, string $pathPrefix
159159
[
160160
new Arg(
161161
new Node\Expr\New_(
162-
new Node\Name('Operators'),
162+
new Node\Name('Internal\\Operators'),
163163
[
164164
new Arg(
165165
new Node\Expr\Variable('browser'),
@@ -239,7 +239,7 @@ public static function generate(Configuration $configuration, string $pathPrefix
239239
'routers',
240240
),
241241
new Node\Expr\New_(
242-
new Node\Name('Routers'),
242+
new Node\Name('Internal\\Routers'),
243243
[
244244
new Arg(
245245
new Node\Expr\Variable('browser'),
@@ -374,7 +374,7 @@ public static function generate(Configuration $configuration, string $pathPrefix
374374
),
375375
);
376376
$chunkCountClasses[] = $cc = new ChunkCount(
377-
'Router\\' . (new Convert($method))->toPascal() . '\\' . (new Convert(NumberToWords::transformNumber('en', $chunkCount)))->toPascal(),
377+
'Internal\\Router\\' . (new Convert($method))->toPascal() . '\\' . (new Convert(NumberToWords::transformNumber('en', $chunkCount)))->toPascal(),
378378
$returnTypes,
379379
$docBlockReturnTypes,
380380
self::traverseOperations(
@@ -1029,7 +1029,7 @@ private static function createRouter(string $pathPrefix, string $namespace, Rout
10291029
)->addParam(
10301030
(new PrivatePromotedPropertyAsParam('responseSchemaValidator'))->setType('\League\OpenAPIValidation\Schema\SchemaValidator'),
10311031
)->addParam(
1032-
(new PrivatePromotedPropertyAsParam('hydrators'))->setType('\\' . $namespace . 'Hydrators'),
1032+
(new PrivatePromotedPropertyAsParam('hydrators'))->setType('Internal\\Hydrators'),
10331033
)->addParam(
10341034
(new PrivatePromotedPropertyAsParam('browser'))->setType('\\' . Browser::class),
10351035
)->addParam(
@@ -1071,7 +1071,7 @@ private static function createRouterChunkSize(string $pathPrefix, string $namesp
10711071

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

src/Generator/Client/Routers.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function createClassName(
6161
string|null $group,
6262
string $name,
6363
): Router {
64-
$className = rtrim('Router\\' . (new Convert($method))->toPascal() . ($group === null ? '' : '\\' . (new Convert($group))->toPascal()), '\\');
64+
$className = rtrim('Internal\\Router\\' . (new Convert($method))->toPascal() . ($group === null ? '' : '\\' . (new Convert($group))->toPascal()), '\\');
6565

6666
return new Router(
6767
$className,

src/Generator/Hydrators.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static function generate(string $pathPrefix, string $namespace, Hydrator
2828
{
2929
$knownScehmas = [];
3030
$factory = new BuilderFactory();
31-
$stmt = $factory->namespace(trim($namespace, '\\'));
31+
$stmt = $factory->namespace(trim($namespace, '\\') . '\\Internal');
3232

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

@@ -296,6 +296,6 @@ public static function generate(string $pathPrefix, string $namespace, Hydrator
296296
);
297297
}
298298

299-
yield new File($pathPrefix, 'Hydrators', $stmt->addStmt($class)->getNode());
299+
yield new File($pathPrefix, 'Internal\\Hydrators', $stmt->addStmt($class)->getNode());
300300
}
301301
}

src/Generator/Operations.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static function generate(Configuration $configuration, string $pathPrefix
4646

4747
$class->addStmt(
4848
$factory->method('__construct')->makePublic()->addParam(
49-
(new PrivatePromotedPropertyAsParam('operators'))->setType('\\' . $configuration->namespace->source . '\Operators'),
49+
(new PrivatePromotedPropertyAsParam('operators'))->setType('Internal\\Operators'),
5050
),
5151
);
5252

@@ -110,7 +110,7 @@ private static function generateOperationsGroup(string $pathPrefix, Configuratio
110110

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

src/Generator/Operators.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class Operators
2929
public static function generate(Configuration $configuration, string $pathPrefix, array $operations, array $operationHydratorMap): iterable
3030
{
3131
$factory = new BuilderFactory();
32-
$stmt = $factory->namespace(trim($configuration->namespace->source, '\\'));
32+
$stmt = $factory->namespace(trim($configuration->namespace->source, '\\') . '\\Internal');
3333

3434
$class = $factory->class('Operators')->makeFinal()->addStmt(
3535
$factory->method('__construct')->makePublic()->addParam(
@@ -41,7 +41,7 @@ public static function generate(Configuration $configuration, string $pathPrefix
4141
)->addParam(
4242
(new PrivatePromotedPropertyAsParam('responseSchemaValidator'))->setType('\League\OpenAPIValidation\Schema\SchemaValidator')->makeReadonly(),
4343
)->addParam(
44-
(new PrivatePromotedPropertyAsParam('hydrators'))->setType('Hydrators')->makeReadonly(),
44+
(new PrivatePromotedPropertyAsParam('hydrators'))->setType('Internal\\Hydrators')->makeReadonly(),
4545
),
4646
);
4747

@@ -111,6 +111,6 @@ public static function generate(Configuration $configuration, string $pathPrefix
111111
]);
112112
}
113113

114-
yield new File($pathPrefix, 'Operators', $stmt->addStmt($class)->getNode());
114+
yield new File($pathPrefix, 'Internal\\Operators', $stmt->addStmt($class)->getNode());
115115
}
116116
}

src/Generator/Routers.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class Routers
2222
public static function generate(Configuration $configuration, string $pathPrefix, ClientRouters $routers): iterable
2323
{
2424
$factory = new BuilderFactory();
25-
$stmt = $factory->namespace(trim($configuration->namespace->source, '\\'));
25+
$stmt = $factory->namespace(trim($configuration->namespace->source, '\\') . '\\Internal');
2626

2727
$class = $factory->class('Routers')->makeFinal()->addStmt(
2828
$factory->method('__construct')->makePublic()->addParam(
@@ -34,7 +34,7 @@ public static function generate(Configuration $configuration, string $pathPrefix
3434
)->addParam(
3535
(new PrivatePromotedPropertyAsParam('responseSchemaValidator'))->setType('\League\OpenAPIValidation\Schema\SchemaValidator')->makeReadonly(),
3636
)->addParam(
37-
(new PrivatePromotedPropertyAsParam('hydrators'))->setType('Hydrators')->makeReadonly(),
37+
(new PrivatePromotedPropertyAsParam('hydrators'))->setType('Internal\\Hydrators')->makeReadonly(),
3838
),
3939
);
4040

@@ -132,6 +132,6 @@ public static function generate(Configuration $configuration, string $pathPrefix
132132
]);
133133
}
134134

135-
yield new File($pathPrefix, 'Routers', $stmt->addStmt($class)->getNode());
135+
yield new File($pathPrefix, 'Internal\\Routers', $stmt->addStmt($class)->getNode());
136136
}
137137
}

src/Generator/Schema.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public static function generate(string $pathPrefix, Representation\Schema $schem
139139
$schemaClasses = [...self::getUnionTypeSchemas($property->type)];
140140

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

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

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

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

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

src/Generator/WebHook.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ public static function generate(
5050
' */',
5151
])));
5252
$class->addStmt($factory->property('requestSchemaValidator')->setType('\\' . SchemaValidator::class)->makeReadonly()->makePrivate());
53-
$class->addStmt($factory->property('hydrator')->setType('Hydrator\\WebHook' . $className)->makeReadonly()->makePrivate());
53+
$class->addStmt($factory->property('hydrator')->setType('Internal\\Hydrator\\WebHook' . $className)->makeReadonly()->makePrivate());
5454

5555
$constructor = $factory->method('__construct')->makePublic()->addParam(
5656
(new Param('requestSchemaValidator'))->setType('\\' . SchemaValidator::class),
5757
)->addParam(
58-
(new Param('hydrator'))->setType('Hydrator\\WebHook' . $className),
58+
(new Param('hydrator'))->setType('Internal\\Hydrator\\WebHook' . $className),
5959
)->addStmt(
6060
new Node\Expr\Assign(
6161
new Node\Expr\PropertyFetch(
@@ -187,6 +187,6 @@ public static function generate(
187187
$method->addStmts($tmts);
188188
$class->addStmt($method);
189189

190-
yield new File($pathPrefix, 'WebHook\\' . $className, $stmt->addStmt($class)->getNode());
190+
yield new File($pathPrefix, 'Internal\\WebHook\\' . $className, $stmt->addStmt($class)->getNode());
191191
}
192192
}

src/Generator/WebHooks.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ public static function generate(string $pathPrefix, string $namespace, array $we
4242

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

4747
$constructor = $factory->method('__construct')->makePublic()->addParams([
4848
(new Param('requestSchemaValidator'))->setType('\\' . SchemaValidator::class),
49-
(new Param('hydrator'))->setType('Hydrators'),
49+
(new Param('hydrator'))->setType('Internal\\Hydrators'),
5050
])->addStmts([
5151
new Node\Expr\Assign(
5252
new Node\Expr\PropertyFetch(

0 commit comments

Comments
 (0)