Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 38 additions & 38 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ parameters:
count: 1
path: src/Container/DriverInterfaceFactoryFactory.php

-
message: '#^Cannot call static method createFromConfig\(\) on callable\.$#'
identifier: staticMethod.nonObject
count: 1
path: src/Container/PdoDriverFactory.php

-
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\(\)$#'
identifier: method.childParameterType
Expand Down
43 changes: 13 additions & 30 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use PhpDb\Adapter\Profiler\Profiler;
use PhpDb\Adapter\Profiler\ProfilerInterface;
use PhpDb\Container\AdapterAbstractServiceFactory;
use PhpDb\Container\AdapterManager;
use PhpDb\Container\ConnectionInterfaceFactoryFactoryInterface;
use PhpDb\Container\DriverInterfaceFactoryFactoryInterface;
use PhpDb\Container\PlatformInterfaceFactoryFactoryInterface;
Expand All @@ -30,8 +29,7 @@ final class ConfigProvider
public function __invoke(): array
{
return [
'dependencies' => $this->getDependencies(),
AdapterManager::class => $this->getAdapterManagerConfig(),
'dependencies' => $this->getDependencies(),
];
}

Expand All @@ -42,23 +40,6 @@ public function getDependencies(): array
AdapterAbstractServiceFactory::class,
],
'aliases' => [
MetadataInterface::class => Metadata\Source\SqliteMetadata::class,
],
'factories' => [
Metadata\Source\SqliteMetadata::class => Container\MetadataInterfaceFactory::class,
],
'delegators' => [
AdapterManager::class => [
Container\AdapterManagerDelegator::class,
],
],
];
}

public function getAdapterManagerConfig(): array
{
return [
'aliases' => [
'SQLite' => Driver\Pdo\Pdo::class,
'Sqlite' => Driver\Pdo\Pdo::class,
'sqlite' => Driver\Pdo\Pdo::class,
Expand All @@ -78,18 +59,20 @@ public function getAdapterManagerConfig(): array
ConnectionInterfaceFactoryFactoryInterface::class => Container\ConnectionInterfaceFactoryFactory::class,
DriverInterfaceFactoryFactoryInterface::class => Container\DriverInterfaceFactoryFactory::class,
PlatformInterfaceFactoryFactoryInterface::class => Container\PlatformInterfaceFactoryFactory::class,
MetadataInterface::class => Metadata\Source\SqliteMetadata::class,
],
'factories' => [
AdapterInterface::class => Container\AdapterFactory::class,
Driver\Pdo\Connection::class => Container\PdoConnectionFactory::class,
Driver\Pdo\Pdo::class => Container\PdoDriverFactory::class,
Result::class => Container\PdoResultFactory::class,
Statement::class => Container\PdoStatementFactory::class,
Platform\Sqlite::class => Container\PlatformInterfaceFactory::class,
Profiler::class => InvokableFactory::class,
ResultSet\ResultSet::class => InvokableFactory::class,
'factories' => [
AdapterInterface::class => Container\AdapterFactory::class,
Driver\Pdo\Connection::class => Container\PdoConnectionFactory::class,
Driver\Pdo\Pdo::class => Container\PdoDriverFactory::class,
Result::class => Container\PdoResultFactory::class,
Statement::class => Container\PdoStatementFactory::class,
Platform\Sqlite::class => Container\PlatformInterfaceFactory::class,
Profiler::class => InvokableFactory::class,
ResultSet\ResultSet::class => InvokableFactory::class,
Metadata\Source\SqliteMetadata::class => Container\MetadataInterfaceFactory::class,
],
'invokables' => [
'invokables' => [
Container\ConnectionInterfaceFactoryFactory::class
=> Container\ConnectionInterfaceFactoryFactory::class,
Container\DriverInterfaceFactoryFactory::class
Expand Down
20 changes: 8 additions & 12 deletions src/Container/AdapterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use PhpDb\Adapter\Exception\RuntimeException;
use PhpDb\Adapter\Platform\PlatformInterface;
use PhpDb\Adapter\Profiler\ProfilerInterface;
use PhpDb\Container\AdapterManager;
use PhpDb\ResultSet\ResultSetInterface;
use Psr\Container\ContainerInterface;

Expand All @@ -22,9 +21,6 @@ final class AdapterFactory
{
public function __invoke(ContainerInterface $container): AdapterInterface
{
/** @var AdapterManager $adapterManager */
$adapterManager = $container->get(AdapterManager::class);

/** @var array $config */
$config = $container->get('config');

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

if (! $adapterManager->has($driver)) {
if (! $container->has($driver)) {
throw new ServiceNotFoundException(sprintf(
'Database driver "%s" is not registered in the adapter manager.',
$driver
));
}

/** @var DriverInterface|PdoDriverInterface $driverInstance */
$driverInstance = $adapterManager->get($driver);
$driverInstance = $container->get($driver);

if (! $adapterManager->has(PlatformInterface::class)) {
if (! $container->has(PlatformInterface::class)) {
throw new ServiceNotFoundException(sprintf(
'Database platform "%s" is not registered in the adapter manager.',
PlatformInterface::class
));
}

/** @var PlatformInterface $platformInstance */
$platformInstance = $adapterManager->get(PlatformInterface::class);
$platformInstance = $container->get(PlatformInterface::class);

if (! $adapterManager->has(ResultSetInterface::class)) {
if (! $container->has(ResultSetInterface::class)) {
throw new ServiceNotFoundException(sprintf(
'ResultSet "%s" is not registered in the adapter manager.',
ResultSetInterface::class
));
}

/** @var ResultSetInterface $resultSetInstance */
$resultSetInstance = $adapterManager->get(ResultSetInterface::class);
$resultSetInstance = $container->get(ResultSetInterface::class);

/** @var ProfilerInterface|null $profilerInstanceOrNull */
$profilerInstanceOrNull = $adapterManager->has(ProfilerInterface::class)
? $adapterManager->get(ProfilerInterface::class)
$profilerInstanceOrNull = $container->has(ProfilerInterface::class)
? $container->get(ProfilerInterface::class)
: null;

return new Adapter(
Expand Down
Loading