Skip to content

Commit 742f5b5

Browse files
authored
Merge pull request #1 from driftphp/feature/some-naming-fixes
Feature/some naming fixes
2 parents e65499b + 06f0c78 commit 742f5b5

File tree

8 files changed

+54
-36
lines changed

8 files changed

+54
-36
lines changed

DependencyInjection/CompilerPass/PostgresqlCompilerPass.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,46 +22,49 @@
2222
use Symfony\Component\DependencyInjection\Definition;
2323
use Symfony\Component\DependencyInjection\Reference;
2424

25+
/**
26+
* Class PostgresqlCompilerPass.
27+
*/
2528
class PostgresqlCompilerPass implements CompilerPassInterface
2629
{
2730
/**
2831
* You can modify the container here before it is dumped to PHP code.
2932
*/
3033
public function process(ContainerBuilder $container)
3134
{
32-
$connectionsConfiguration = $container->getParameter('postgresql.connections_configuration');
33-
if (empty($connectionsConfiguration)) {
35+
$clientsConfiguration = $container->getParameter('postgresql.clients_configuration');
36+
if (empty($clientsConfiguration)) {
3437
return;
3538
}
3639

37-
foreach ($connectionsConfiguration as $connectionName => $connectionConfiguration) {
38-
$connectionAlias = $this->createConnection($container, $connectionConfiguration);
40+
foreach ($clientsConfiguration as $clientName => $clientConfiguration) {
41+
$clientAlias = $this->createclient($container, $clientConfiguration);
3942

4043
$container->setAlias(
41-
"postgresql.{$connectionName}_connection",
42-
$connectionAlias
44+
"postgresql.{$clientName}_client",
45+
$clientAlias
4346
);
4447

45-
$container->setAlias(Client::class, $connectionAlias);
46-
$container->registerAliasForArgument($connectionAlias, Client::class, "{$connectionName} connection");
48+
$container->setAlias(Client::class, $clientAlias);
49+
$container->registerAliasForArgument($clientAlias, Client::class, "{$clientName} client");
4750
}
4851
}
4952

5053
/**
51-
* Create connection and return it's reference.
54+
* Create client and return it's reference.
5255
*
5356
* @param ContainerBuilder $container
5457
* @param array $configuration
5558
*
5659
* @return string
5760
*/
58-
private function createConnection(
61+
private function createclient(
5962
ContainerBuilder $container,
6063
array $configuration
6164
): string {
6265
ksort($configuration);
63-
$connectionHash = substr(md5(json_encode($configuration)), 0, 10);
64-
$definitionName = "postgresql.connection.$connectionHash";
66+
$clientHash = substr(md5(json_encode($configuration)), 0, 10);
67+
$definitionName = "postgresql.client.$clientHash";
6568

6669
if (!$container->hasDefinition($definitionName)) {
6770
$definition = new Definition(Client::class, [$configuration, new Reference(LoopInterface::class)]);

DependencyInjection/PostgresqlConfiguration.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
use Mmoreram\BaseBundle\DependencyInjection\BaseConfiguration;
1919
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
2020

21+
/**
22+
* Class PostgresqlConfiguration.
23+
*/
2124
class PostgresqlConfiguration extends BaseConfiguration
2225
{
2326
/**
@@ -29,7 +32,7 @@ protected function setupTree(ArrayNodeDefinition $rootNode)
2932
{
3033
$rootNode
3134
->children()
32-
->arrayNode('connections')
35+
->arrayNode('clients')
3336
->prototype('array')
3437
->children()
3538
->scalarNode('host')

DependencyInjection/PostgresqlExtension.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* file that was distributed with this source code.
88
*
99
* Feel free to edit as you please, and have fun.
10+
*
11+
* @author Marc Morera <yuhu@mmoreram.com>
1012
*/
1113

1214
declare(strict_types=1);
@@ -16,6 +18,9 @@
1618
use Mmoreram\BaseBundle\DependencyInjection\BaseExtension;
1719
use Symfony\Component\Config\Definition\ConfigurationInterface;
1820

21+
/**
22+
* Class PostgresqlExtension.
23+
*/
1924
class PostgresqlExtension extends BaseExtension
2025
{
2126
/**
@@ -89,7 +94,7 @@ protected function getConfigurationInstance(): ? ConfigurationInterface
8994
protected function getParametrizationValues(array $config): array
9095
{
9196
return [
92-
'postgresql.connections_configuration' => $config['connections'],
97+
'postgresql.clients_configuration' => $config['clients'],
9398
];
9499
}
95100
}

PostgresqlBundle.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* file that was distributed with this source code.
88
*
99
* Feel free to edit as you please, and have fun.
10+
*
11+
* @author Marc Morera <yuhu@mmoreram.com>
1012
*/
1113

1214
declare(strict_types=1);

Tests/AutowiringTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ protected static function getKernel(): KernelInterface
4747
'test' => true,
4848
],
4949
'imports' => [
50-
['resource' => __DIR__ .'/autowiring.yml'],
50+
['resource' => __DIR__.'/autowiring.yml'],
5151
],
5252
'services' => [
5353
'reactphp.event_loop' => [
@@ -59,7 +59,7 @@ protected static function getKernel(): KernelInterface
5959
],
6060
],
6161
'postgresql' => [
62-
'connections' => [
62+
'clients' => [
6363
'users' => [
6464
'host' => '127.0.0.1',
6565
'database' => 'orders',

Tests/ConfigurationTest.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* file that was distributed with this source code.
88
*
99
* Feel free to edit as you please, and have fun.
10+
*
11+
* @author Marc Morera <yuhu@mmoreram.com>
1012
*/
1113

1214
declare(strict_types=1);
@@ -45,7 +47,7 @@ protected static function getKernel(): KernelInterface
4547
'test' => true,
4648
],
4749
'imports' => [
48-
['resource' => __DIR__ .'/clients.yml'],
50+
['resource' => __DIR__.'/clients.yml'],
4951
],
5052
'services' => [
5153
'reactphp.event_loop' => [
@@ -57,7 +59,7 @@ protected static function getKernel(): KernelInterface
5759
],
5860
],
5961
'postgresql' => [
60-
'connections' => [
62+
'clients' => [
6163
'users' => [
6264
'host' => '127.0.0.1',
6365
'user' => 'user',
@@ -72,10 +74,10 @@ protected static function getKernel(): KernelInterface
7274
/**
7375
* Test.
7476
*/
75-
public function testProperConnection()
77+
public function testProperClient()
7678
{
77-
$connection = static::get('postgresql.users_connection.test');
78-
$this->assertInstanceOf(Client::class, $connection);
79-
$this->assertInstanceOf(Client::class, $connection);
79+
$client = static::get('postgresql.users_client.test');
80+
$this->assertInstanceOf(Client::class, $client);
81+
$this->assertInstanceOf(Client::class, $client);
8082
}
8183
}

Tests/Services/AService.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,43 +17,46 @@
1717

1818
use PgAsync\Client;
1919

20+
/**
21+
* Class AService.
22+
*/
2023
class AService
2124
{
2225
/**
2326
* @var Client
2427
*/
25-
private $connection1;
28+
private $client1;
2629

2730
/**
2831
* @var Client
2932
*/
30-
private $connection2;
33+
private $client2;
3134

3235
/**
3336
* @var Client
3437
*/
35-
private $connection3;
38+
private $client3;
3639

3740
/**
3841
* AService constructor.
3942
*
40-
* @param Client $connection1
41-
* @param Client $connection2
42-
* @param Client $connection3
43+
* @param Client $client1
44+
* @param Client $client2
45+
* @param Client $client3
4346
*/
44-
public function __construct(Client $usersConnection, Client $ordersConnection, Client $users2Connection)
47+
public function __construct(Client $usersClient, Client $ordersClient, Client $users2Client)
4548
{
46-
$this->connection1 = $usersConnection;
47-
$this->connection2 = $ordersConnection;
48-
$this->connection3 = $users2Connection;
49+
$this->client1 = $usersClient;
50+
$this->client2 = $ordersClient;
51+
$this->client3 = $users2Client;
4952
}
5053

5154
/**
5255
* Are equal.
5356
*/
5457
public function areOK(): bool
5558
{
56-
return $this->connection1 !== $this->connection2
57-
&& $this->connection1 === $this->connection3;
59+
return $this->client1 !== $this->client2
60+
&& $this->client1 === $this->client3;
5861
}
5962
}

Tests/clients.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
services:
22

3-
postgresql.users_connection.test:
4-
alias: postgresql.users_connection
3+
postgresql.users_client.test:
4+
alias: postgresql.users_client
55
public: true

0 commit comments

Comments
 (0)