Skip to content

Commit f3807d1

Browse files
authored
Make the code generator manage the async-aws/core requirement (#1465)
As the registry now supports properly combining multiple min versions for a semver requirement, we can make the code generator manage the async-aws/core requirement of generated services even when they don't require special features instead of relying on the template to add it. The generators now also avoid adding a requirement on async-aws/core if the generator code is inside the Core package to avoid generating a self-referencing requirement (this was fine before only because the Sts client was not relying on the special features that were adding such a requirement). This also removes the json extension from the template as it is managed by the code generator anyway and makes the symfony/polyfill-uuid requirement cleanable in case a service does not need it anymore.
1 parent 72cca34 commit f3807d1

File tree

7 files changed

+28
-10
lines changed

7 files changed

+28
-10
lines changed

src/CodeGenerator/src/File/ComposerWriter.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public function setRequirements(string $namespace, array $requirements, bool $cl
2828
$content['require']['ext-dom'],
2929
$content['require']['ext-SimpleXML'],
3030
$content['require']['ext-filter'],
31+
$content['require']['async-aws/core'],
32+
$content['require']['symfony/polyfill-uuid'],
3133
);
3234
}
3335
$content['require'] = $requirements + $content['require'];

src/CodeGenerator/src/Generator/ClientGenerator.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace AsyncAws\CodeGenerator\Generator;
66

77
use AsyncAws\CodeGenerator\Definition\ServiceDefinition;
8+
use AsyncAws\CodeGenerator\Generator\Composer\RequirementsRegistry;
89
use AsyncAws\CodeGenerator\Generator\Naming\ClassName;
910
use AsyncAws\CodeGenerator\Generator\Naming\NamespaceRegistry;
1011
use AsyncAws\CodeGenerator\Generator\PhpGenerator\ClassRegistry;
@@ -35,10 +36,16 @@ class ClientGenerator
3536
*/
3637
private $namespaceRegistry;
3738

38-
public function __construct(ClassRegistry $classRegistry, NamespaceRegistry $namespaceRegistry)
39+
/**
40+
* @var RequirementsRegistry
41+
*/
42+
private $requirementsRegistry;
43+
44+
public function __construct(ClassRegistry $classRegistry, NamespaceRegistry $namespaceRegistry, RequirementsRegistry $requirementsRegistry)
3945
{
4046
$this->classRegistry = $classRegistry;
4147
$this->namespaceRegistry = $namespaceRegistry;
48+
$this->requirementsRegistry = $requirementsRegistry;
4249
}
4350

4451
/**
@@ -47,6 +54,9 @@ public function __construct(ClassRegistry $classRegistry, NamespaceRegistry $nam
4754
public function generate(ServiceDefinition $definition): ClassName
4855
{
4956
$className = $this->namespaceRegistry->getClient($definition);
57+
if (0 !== strpos($className->getFqdn(), 'AsyncAws\Core\\')) {
58+
$this->requirementsRegistry->addRequirement('async-aws/core', '^1.9');
59+
}
5060
$classBuilder = $this->classRegistry->register($className->getFqdn(), true);
5161

5262
$supportedVersions = eval(sprintf('class A%s extends %s {

src/CodeGenerator/src/Generator/InputGenerator.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,9 @@ private function inputClassRequestGetters(StructureShape $inputShape, ClassBuild
321321
}
322322

323323
if ('querystring' === $requestPart && $usesEndpointDiscovery) {
324-
$this->requirementsRegistry->addRequirement('async-aws/core', '^1.19');
324+
if (0 !== strpos($classBuilder->getClassName()->getFqdn(), 'AsyncAws\Core\\')) {
325+
$this->requirementsRegistry->addRequirement('async-aws/core', '^1.19');
326+
}
325327
}
326328

327329
$memberShape = $member->getShape();
@@ -452,7 +454,9 @@ private function inputClassRequestGetters(StructureShape $inputShape, ClassBuild
452454
$uriStringCode = preg_replace('/(^""\.|\.""$|\.""\.)/', '', $uriStringCode);
453455

454456
if ($usesEndpointDiscovery && '"/"' !== $uriStringCode) {
455-
$this->requirementsRegistry->addRequirement('async-aws/core', '^1.19');
457+
if (0 !== strpos($classBuilder->getClassName()->getFqdn(), 'AsyncAws\Core\\')) {
458+
$this->requirementsRegistry->addRequirement('async-aws/core', '^1.19');
459+
}
456460
}
457461

458462
$body['uri'] .= '$uriString = ' . $uriStringCode . ';';

src/CodeGenerator/src/Generator/OperationGenerator.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ private function setMethodBody(Method $method, Operation $operation, ClassName $
204204
}
205205

206206
if ($operation->requiresEndpointDiscovery()) {
207-
$this->requirementsRegistry->addRequirement('async-aws/core', '^1.16');
207+
if (0 !== strpos($classBuilder->getClassName()->getFqdn(), 'AsyncAws\Core\\')) {
208+
$this->requirementsRegistry->addRequirement('async-aws/core', '^1.16');
209+
}
208210
$endpointOperation = $operation->getService()->findEndpointOperationName();
209211

210212
if (null !== $endpointOperation) {
@@ -214,7 +216,9 @@ private function setMethodBody(Method $method, Operation $operation, ClassName $
214216
$extra .= ", 'requiresEndpointDiscovery' => true";
215217
}
216218
if ($operation->usesEndpointDiscovery()) {
217-
$this->requirementsRegistry->addRequirement('async-aws/core', '^1.16');
219+
if (0 !== strpos($classBuilder->getClassName()->getFqdn(), 'AsyncAws\Core\\')) {
220+
$this->requirementsRegistry->addRequirement('async-aws/core', '^1.16');
221+
}
218222
$endpointOperation = $operation->getService()->findEndpointOperationName();
219223

220224
if (null !== $endpointOperation) {

src/CodeGenerator/src/Generator/ServiceGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function __construct(ClassRegistry $classRegistry, RequirementsRegistry $
119119

120120
public function client(): ClientGenerator
121121
{
122-
return $this->client ?? $this->client = new ClientGenerator($this->classRegistry, $this->namespaceRegistry);
122+
return $this->client ?? $this->client = new ClientGenerator($this->classRegistry, $this->namespaceRegistry, $this->requirementsRegistry);
123123
}
124124

125125
public function operation(): OperationGenerator

src/Service/.template/composer.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
"foobar"
1212
],
1313
"require": {
14-
"php": "^7.2.5 || ^8.0",
15-
"ext-json": "*",
16-
"async-aws/core": "^1.9"
14+
"php": "^7.2.5 || ^8.0"
1715
},
1816
"autoload": {
1917
"psr-4": {

src/Service/CloudFormation/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"php": "^7.2.5 || ^8.0",
1515
"ext-SimpleXML": "*",
1616
"ext-filter": "*",
17-
"async-aws/core": "^1.2"
17+
"async-aws/core": "^1.9"
1818
},
1919
"autoload": {
2020
"psr-4": {

0 commit comments

Comments
 (0)