Skip to content

Commit f28df9b

Browse files
authored
Merge pull request #23 from tyrsson/explore-removing-adapter-manager
Removes all usage of adapter manager and removes unused use statements.
2 parents 59ac5ea + 48df1a9 commit f28df9b

13 files changed

+127
-209
lines changed

composer.lock

Lines changed: 38 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan-baseline.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ parameters:
66
count: 1
77
path: src/Container/DriverInterfaceFactoryFactory.php
88

9-
-
10-
message: '#^Cannot call static method createFromConfig\(\) on callable\.$#'
11-
identifier: staticMethod.nonObject
12-
count: 1
13-
path: src/Container/PdoDriverFactory.php
14-
159
-
1610
message: '#^Parameter \#1 \$name \(string\) of method PhpDb\\Adapter\\Sqlite\\Driver\\Pdo\\Connection\:\:getLastGeneratedValue\(\) should be compatible with parameter \$name \(null\) of method PhpDb\\Adapter\\Driver\\ConnectionInterface\:\:getLastGeneratedValue\(\)$#'
1711
identifier: method.childParameterType

src/ConfigProvider.php

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use PhpDb\Adapter\Profiler\Profiler;
1919
use PhpDb\Adapter\Profiler\ProfilerInterface;
2020
use PhpDb\Container\AdapterAbstractServiceFactory;
21-
use PhpDb\Container\AdapterManager;
2221
use PhpDb\Container\ConnectionInterfaceFactoryFactoryInterface;
2322
use PhpDb\Container\DriverInterfaceFactoryFactoryInterface;
2423
use PhpDb\Container\PlatformInterfaceFactoryFactoryInterface;
@@ -30,8 +29,7 @@ final class ConfigProvider
3029
public function __invoke(): array
3130
{
3231
return [
33-
'dependencies' => $this->getDependencies(),
34-
AdapterManager::class => $this->getAdapterManagerConfig(),
32+
'dependencies' => $this->getDependencies(),
3533
];
3634
}
3735

@@ -42,23 +40,6 @@ public function getDependencies(): array
4240
AdapterAbstractServiceFactory::class,
4341
],
4442
'aliases' => [
45-
MetadataInterface::class => Metadata\Source\SqliteMetadata::class,
46-
],
47-
'factories' => [
48-
Metadata\Source\SqliteMetadata::class => Container\MetadataInterfaceFactory::class,
49-
],
50-
'delegators' => [
51-
AdapterManager::class => [
52-
Container\AdapterManagerDelegator::class,
53-
],
54-
],
55-
];
56-
}
57-
58-
public function getAdapterManagerConfig(): array
59-
{
60-
return [
61-
'aliases' => [
6243
'SQLite' => Driver\Pdo\Pdo::class,
6344
'Sqlite' => Driver\Pdo\Pdo::class,
6445
'sqlite' => Driver\Pdo\Pdo::class,
@@ -78,18 +59,20 @@ public function getAdapterManagerConfig(): array
7859
ConnectionInterfaceFactoryFactoryInterface::class => Container\ConnectionInterfaceFactoryFactory::class,
7960
DriverInterfaceFactoryFactoryInterface::class => Container\DriverInterfaceFactoryFactory::class,
8061
PlatformInterfaceFactoryFactoryInterface::class => Container\PlatformInterfaceFactoryFactory::class,
62+
MetadataInterface::class => Metadata\Source\SqliteMetadata::class,
8163
],
82-
'factories' => [
83-
AdapterInterface::class => Container\AdapterFactory::class,
84-
Driver\Pdo\Connection::class => Container\PdoConnectionFactory::class,
85-
Driver\Pdo\Pdo::class => Container\PdoDriverFactory::class,
86-
Result::class => Container\PdoResultFactory::class,
87-
Statement::class => Container\PdoStatementFactory::class,
88-
Platform\Sqlite::class => Container\PlatformInterfaceFactory::class,
89-
Profiler::class => InvokableFactory::class,
90-
ResultSet\ResultSet::class => InvokableFactory::class,
64+
'factories' => [
65+
AdapterInterface::class => Container\AdapterFactory::class,
66+
Driver\Pdo\Connection::class => Container\PdoConnectionFactory::class,
67+
Driver\Pdo\Pdo::class => Container\PdoDriverFactory::class,
68+
Result::class => Container\PdoResultFactory::class,
69+
Statement::class => Container\PdoStatementFactory::class,
70+
Platform\Sqlite::class => Container\PlatformInterfaceFactory::class,
71+
Profiler::class => InvokableFactory::class,
72+
ResultSet\ResultSet::class => InvokableFactory::class,
73+
Metadata\Source\SqliteMetadata::class => Container\MetadataInterfaceFactory::class,
9174
],
92-
'invokables' => [
75+
'invokables' => [
9376
Container\ConnectionInterfaceFactoryFactory::class
9477
=> Container\ConnectionInterfaceFactoryFactory::class,
9578
Container\DriverInterfaceFactoryFactory::class

src/Container/AdapterFactory.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use PhpDb\Adapter\Exception\RuntimeException;
1313
use PhpDb\Adapter\Platform\PlatformInterface;
1414
use PhpDb\Adapter\Profiler\ProfilerInterface;
15-
use PhpDb\Container\AdapterManager;
1615
use PhpDb\ResultSet\ResultSetInterface;
1716
use Psr\Container\ContainerInterface;
1817

@@ -22,9 +21,6 @@ final class AdapterFactory
2221
{
2322
public function __invoke(ContainerInterface $container): AdapterInterface
2423
{
25-
/** @var AdapterManager $adapterManager */
26-
$adapterManager = $container->get(AdapterManager::class);
27-
2824
/** @var array $config */
2925
$config = $container->get('config');
3026

@@ -38,39 +34,39 @@ public function __invoke(ContainerInterface $container): AdapterInterface
3834
/** @var string $driver */
3935
$driver = $dbConfig['driver'];
4036

41-
if (! $adapterManager->has($driver)) {
37+
if (! $container->has($driver)) {
4238
throw new ServiceNotFoundException(sprintf(
4339
'Database driver "%s" is not registered in the adapter manager.',
4440
$driver
4541
));
4642
}
4743

4844
/** @var DriverInterface|PdoDriverInterface $driverInstance */
49-
$driverInstance = $adapterManager->get($driver);
45+
$driverInstance = $container->get($driver);
5046

51-
if (! $adapterManager->has(PlatformInterface::class)) {
47+
if (! $container->has(PlatformInterface::class)) {
5248
throw new ServiceNotFoundException(sprintf(
5349
'Database platform "%s" is not registered in the adapter manager.',
5450
PlatformInterface::class
5551
));
5652
}
5753

5854
/** @var PlatformInterface $platformInstance */
59-
$platformInstance = $adapterManager->get(PlatformInterface::class);
55+
$platformInstance = $container->get(PlatformInterface::class);
6056

61-
if (! $adapterManager->has(ResultSetInterface::class)) {
57+
if (! $container->has(ResultSetInterface::class)) {
6258
throw new ServiceNotFoundException(sprintf(
6359
'ResultSet "%s" is not registered in the adapter manager.',
6460
ResultSetInterface::class
6561
));
6662
}
6763

6864
/** @var ResultSetInterface $resultSetInstance */
69-
$resultSetInstance = $adapterManager->get(ResultSetInterface::class);
65+
$resultSetInstance = $container->get(ResultSetInterface::class);
7066

7167
/** @var ProfilerInterface|null $profilerInstanceOrNull */
72-
$profilerInstanceOrNull = $adapterManager->has(ProfilerInterface::class)
73-
? $adapterManager->get(ProfilerInterface::class)
68+
$profilerInstanceOrNull = $container->has(ProfilerInterface::class)
69+
? $container->get(ProfilerInterface::class)
7470
: null;
7571

7672
return new Adapter(

0 commit comments

Comments
 (0)