Skip to content

Commit 5000974

Browse files
authored
Added some more docs to SymfonyBundle (#169)
* Added some more docs to SymfonyBundle * Rename async_aws.services to async_aws.clients
1 parent 96994a5 commit 5000974

File tree

9 files changed

+66
-56
lines changed

9 files changed

+66
-56
lines changed

DependencyInjection/AsyncAwsExtension.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ private function registerConfiguredServices(ContainerBuilder $container, array $
2828
$availableServices = AwsPackagesProvider::getAllServices();
2929
$usedServices = [];
3030
$defaultConfig = $config;
31-
unset($defaultConfig['services']);
31+
unset($defaultConfig['clients']);
3232

33-
foreach ($config['services'] as $name => $data) {
34-
$client = $availableServices[$data['type']]['client'];
33+
foreach ($config['clients'] as $name => $data) {
34+
$client = $availableServices[$data['type']]['class'];
3535
if (!class_exists($client)) {
3636
throw new InvalidConfigurationException(sprintf('You have configured "async_aws.%s" but the "%s" package is not installed. Try running "composer require %s"', $name, $name, $availableServices[$name]['package']));
3737
}
@@ -54,14 +54,14 @@ private function registerInstalledServices(ContainerBuilder $container, array $c
5454
return $usedServices;
5555
}
5656

57-
unset($config['services']);
57+
unset($config['clients']);
5858
$availableServices = AwsPackagesProvider::getAllServices();
5959
foreach ($availableServices as $name => $data) {
6060
if (\array_key_exists($name, $usedServices)) {
6161
continue;
6262
}
6363

64-
$client = $data['client'];
64+
$client = $data['class'];
6565
if (!class_exists($client)) {
6666
continue;
6767
}
@@ -87,7 +87,7 @@ private function addServiceDefinition(ContainerBuilder $container, string $name,
8787
$definition->addArgument(isset($config['credential_provider']) ? new Reference($config['credential_provider']) : null);
8888
$definition->addArgument(isset($config['http_client']) ? new Reference($config['http_client']) : null);
8989
$definition->addArgument($logger);
90-
$container->setDefinition(sprintf('async_aws.service.%s', $name), $definition);
90+
$container->setDefinition(sprintf('async_aws.client.%s', $name), $definition);
9191
}
9292

9393
private function autowireServices(ContainerBuilder $container, array $usedServices): void
@@ -99,7 +99,7 @@ private function autowireServices(ContainerBuilder $container, array $usedServic
9999
continue;
100100
}
101101

102-
$serviceId = sprintf('async_aws.service.%s', $name);
102+
$serviceId = sprintf('async_aws.client.%s', $name);
103103
if (isset($awsServices[$name])) {
104104
$container->setAlias($client, $serviceId);
105105

DependencyInjection/AwsPackagesProvider.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ public static function getAllServices(): array
1010
{
1111
return [
1212
's3' => [
13-
'client' => \AsyncAws\S3\S3Client::class,
13+
'class' => \AsyncAws\S3\S3Client::class,
1414
'package' => 'async-aws/s3',
1515
],
1616
'ses' => [
17-
'client' => \AsyncAws\Ses\SesClient::class,
17+
'class' => \AsyncAws\Ses\SesClient::class,
1818
'package' => 'async-aws/ses',
1919
],
2020
'sqs' => [
21-
'client' => \AsyncAws\Sqs\SqsClient::class,
21+
'class' => \AsyncAws\Sqs\SqsClient::class,
2222
'package' => 'async-aws/sqs',
2323
],
2424
'sts' => [
25-
'client' => \AsyncAws\Core\Sts\StsClient::class,
25+
'class' => \AsyncAws\Core\Sts\StsClient::class,
2626
'package' => 'async-aws/core',
2727
],
2828
'sns' => [
29-
'client' => \AsyncAws\Sns\SnsClient::class,
29+
'class' => \AsyncAws\Sns\SnsClient::class,
3030
'package' => 'async-aws/sns',
3131
],
3232
];

DependencyInjection/Configuration.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@ public function getConfigTreeBuilder()
1717
/** @var ArrayNodeDefinition $rootNode */
1818
$rootNode = $treeBuilder->getRootNode();
1919
$rootNode
20-
->fixXmlConfig('service')
20+
->fixXmlConfig('client')
2121
->children()
22-
->booleanNode('register_service')->info('If set to false, no service will be created.')->defaultTrue()->end()
22+
->booleanNode('register_service')->info('If set to false, no services will be created.')->defaultTrue()->end()
2323
->scalarNode('credential_provider')->info('A service name for AsyncAws\Core\Credentials\CredentialProvider.')->defaultNull()->end()
2424
->scalarNode('http_client')->info('A service name for Symfony\Contracts\HttpClient\HttpClientInterface.')->defaultNull()->end()
2525
->scalarNode('logger')->info('A service name for Psr\Log\LoggerInterface.')->end()
26-
->arrayNode('config')->normalizeKeys(false)->prototype('variable')->end()->end()
26+
->arrayNode('config')->info('Default config that will be merged will all services.')->normalizeKeys(false)->prototype('variable')->end()->end()
2727

28-
->arrayNode('services')
28+
->arrayNode('clients')
2929
->beforeNormalization()->always()->then(\Closure::fromCallable([$this, 'validateType']))->end()
3030
->useAttributeAsKey('name')
3131
->arrayPrototype()
3232
->children()
33-
->booleanNode('register_service')->info('If set to false, no service will be created.')->defaultTrue()->end()
34-
->arrayNode('config')->normalizeKeys(false)->prototype('variable')->end()->end()
33+
->booleanNode('register_service')->info('If set to false, no service will be created for this AWS type.')->defaultTrue()->end()
34+
->arrayNode('config')->info('Configuration specific to this service.')->normalizeKeys(false)->prototype('variable')->end()->end()
3535
->enumNode('type')->info('A valid AWS type. The service name will be used as default. ')->values(AwsPackagesProvider::getServiceNames())->end()
3636
->scalarNode('credential_provider')->info('A service name for AsyncAws\Core\Credentials\CredentialProvider.')->end()
3737
->scalarNode('http_client')->info('A service name for Symfony\Contracts\HttpClient\HttpClientInterface.')->end()
@@ -44,24 +44,24 @@ public function getConfigTreeBuilder()
4444
return $treeBuilder;
4545
}
4646

47-
private static function validateType(array $services)
47+
private static function validateType(array $clients)
4848
{
4949
$awsServices = AwsPackagesProvider::getServiceNames();
50-
foreach ($services as $name => $config) {
50+
foreach ($clients as $name => $config) {
5151
if (\in_array($name, $awsServices)) {
5252
if (isset($config['type']) && $name !== $config['type']) {
5353
throw new InvalidConfigurationException(sprintf('You cannot define a service named "%s" with type "%s". That is super confusing.', $name, $config['type']));
5454
}
55-
$services[$name]['type'] = $name;
55+
$clients[$name]['type'] = $name;
5656
} elseif (!isset($config['type'])) {
5757
if (!\in_array($name, $awsServices)) {
58-
throw new InvalidConfigurationException(sprintf('The "async_aws.service.%s" does not have a type. We were unable to guess what AWS service you want. Please add "aws.service.%s.type".', $name, $name));
58+
throw new InvalidConfigurationException(sprintf('The "async_aws.client.%s" does not have a type. We were unable to guess what AWS service you want. Please add "aws.service.%s.type".', $name, $name));
5959
}
6060

61-
$services[$name]['type'] = $name;
61+
$clients[$name]['type'] = $name;
6262
}
6363
}
6464

65-
return $services;
65+
return $clients;
6666
}
6767
}

README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,21 @@ composer require async-aws/async-aws-bundle
1313

1414
## Configure
1515

16+
The bundle will autowire all AsyncAws clients that you have installed. You can
17+
provide default configuration to all clients and specific configuration of each
18+
service you define.
19+
1620
```yaml
21+
22+
# config/packages/async_aws.yaml
23+
# This example assume you have installed core, ses, sqs and S3
24+
#
25+
1726
async_aws:
1827
config: # Will be merged with other configuration
1928
region: eu-central-1
2029

21-
services:
30+
clients:
2231
ses: ~ # This will complain if we dont have that package installed
2332
sqs:
2433
config:
@@ -31,13 +40,14 @@ The config above will create the following services:
3140
3241
| Service name | Autowired with |
3342
| -------------------------- | ------------------------------- |
34-
| `async_aws.service.ses` | \AsyncAws\Ses\SesClient
35-
| `async_aws.service.sqs` | \AsyncAws\Sqs\SqsClient
36-
| `async_aws.service.foobar` | \AsyncAws\Sqs\SqsClient $foobar
37-
| `async_aws.service.s3` | \AsyncAws\S3\S3Client
43+
| `async_aws.client.ses` | \AsyncAws\Ses\SesClient
44+
| `async_aws.client.sqs` | \AsyncAws\Sqs\SqsClient
45+
| `async_aws.client.foobar` | \AsyncAws\Sqs\SqsClient $foobar
46+
| `async_aws.client.s3` | \AsyncAws\S3\S3Client
47+
| `async_aws.client.sts` | \AsyncAws\Core\Sts\StsClient
3848

3949
For a complete reference of the configuration please run:
4050

4151
```cli
42-
php bin/console config:dump-reference asyncaws
52+
php bin/console config:dump-reference async_aws
4353
```

Tests/Functional/BundleInitializationTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ public function testInitBundle()
2828
$kernel->addConfigFile(__DIR__ . '/Resources/config/default.yaml');
2929
$this->bootKernel();
3030

31-
$this->assertServiceExists('async_aws.service.s3', S3Client::class);
32-
$this->assertServiceExists('async_aws.service.sqs', SqsClient::class);
33-
$this->assertServiceExists('async_aws.service.ses', SesClient::class);
34-
$this->assertServiceExists('async_aws.service.foobar', SqsClient::class);
31+
$this->assertServiceExists('async_aws.client.s3', S3Client::class);
32+
$this->assertServiceExists('async_aws.client.sqs', SqsClient::class);
33+
$this->assertServiceExists('async_aws.client.ses', SesClient::class);
34+
$this->assertServiceExists('async_aws.client.foobar', SqsClient::class);
3535

3636
// Test autowired clients
3737
$this->assertServiceExists(S3Client::class, S3Client::class);
@@ -52,9 +52,9 @@ public function testEmptyConfig()
5252
$kernel->addConfigFile(__DIR__ . '/Resources/config/empty.yaml');
5353
$this->bootKernel();
5454

55-
$this->assertServiceExists('async_aws.service.s3', S3Client::class);
56-
$this->assertServiceExists('async_aws.service.sqs', SqsClient::class);
57-
$this->assertServiceExists('async_aws.service.ses', SesClient::class);
55+
$this->assertServiceExists('async_aws.client.s3', S3Client::class);
56+
$this->assertServiceExists('async_aws.client.sqs', SqsClient::class);
57+
$this->assertServiceExists('async_aws.client.ses', SesClient::class);
5858

5959
// Test autowired clients
6060
$this->assertServiceExists(S3Client::class, S3Client::class);
@@ -69,8 +69,8 @@ public function testNotRegisterServices()
6969
$this->bootKernel();
7070

7171
$container = $this->getContainer();
72-
self::assertFalse($container->has('async_aws.service.s3'));
73-
self::assertFalse($container->has('async_aws.service.sqs'));
72+
self::assertFalse($container->has('async_aws.client.s3'));
73+
self::assertFalse($container->has('async_aws.client.sqs'));
7474
self::assertFalse($container->has(SqsClient::class));
7575
}
7676

@@ -81,8 +81,8 @@ public function testNotRegisterSqs()
8181
$this->bootKernel();
8282

8383
$container = $this->getContainer();
84-
self::assertTrue($container->has('async_aws.service.s3'));
85-
self::assertFalse($container->has('async_aws.service.sqs'));
84+
self::assertTrue($container->has('async_aws.client.s3'));
85+
self::assertFalse($container->has('async_aws.client.sqs'));
8686
self::assertFalse($container->has(SqsClient::class));
8787
}
8888

Tests/Functional/Resources/config/default.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ framework:
55
async_aws:
66
config:
77
region: eu-central-1
8-
services:
8+
clients:
99
sqs:
1010
config:
1111
region: us-west-1

Tests/Functional/Resources/config/no_service_sqs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ framework:
33
utf8: true
44

55
async_aws:
6-
services:
6+
clients:
77
sqs:
88
register_service: false

Tests/Functional/Resources/config/not_installed_service.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ framework:
55
async_aws:
66
config:
77
region: eu-central-1
8-
services:
8+
clients:
99
sns: ~
1010

Tests/Unit/DependencyInjection/ConfigurationTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,71 +28,71 @@ public function testDefaultValues(): void
2828
'credential_provider' => null,
2929
'http_client' => null,
3030
'config' => [],
31-
'services' => [],
31+
'clients' => [],
3232
]);
3333
}
3434

3535
public function testServiceWithAwsName(): void
3636
{
3737
$this->assertProcessedConfigurationEquals([
38-
['services' => [
38+
['clients' => [
3939
'sqs' => ['config' => ['foo' => 'bar']],
4040
]],
4141
], [
42-
'services' => [
42+
'clients' => [
4343
'sqs' => [
4444
'register_service' => true,
4545
'config' => ['foo' => 'bar'],
4646
'type' => 'sqs',
4747
],
4848
],
49-
], 'services');
49+
], 'clients');
5050
}
5151

5252
public function testServiceWithCustomName(): void
5353
{
5454
$this->assertProcessedConfigurationEquals([
55-
['services' => [
55+
['clients' => [
5656
'foobar' => [
5757
'type' => 'sqs',
5858
],
5959
]],
6060
], [
61-
'services' => [
61+
'clients' => [
6262
'foobar' => [
6363
'register_service' => true,
6464
'type' => 'sqs',
6565
'config' => [],
6666
],
6767
],
68-
], 'services');
68+
], 'clients');
6969
}
7070

7171
public function testServiceWithCustomNameWithoutType(): void
7272
{
7373
$this->assertConfigurationIsInvalid([
74-
['services' => [
74+
['clients' => [
7575
'foobar' => [
7676
],
7777
]],
78-
], 'The "async_aws.service.foobar" does not have a type');
78+
], 'The "async_aws.client.foobar" does not have a type');
7979
}
8080

8181
public function testServiceWithCustomNameWithWrongType(): void
8282
{
8383
$this->assertConfigurationIsInvalid([
84-
['services' => [
84+
['clients' => [
8585
'foobar' => [
8686
'type' => 'blabla',
8787
],
8888
]],
89-
], 'The value "blabla" is not allowed for path "async_aws.services.foobar.type"');
89+
], 'The value "blabla" is not allowed for path "async_aws.clients.foobar.type"');
9090
}
9191

9292
public function testServiceWithAwsNameWithWrongType(): void
9393
{
9494
$this->assertConfigurationIsInvalid([
95-
['services' => [
95+
['clients' => [
9696
'sqs' => [
9797
'type' => 's3',
9898
],

0 commit comments

Comments
 (0)