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
14 changes: 13 additions & 1 deletion src/Container/AdapterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Laminas\Db\Adapter\AdapterInterface;
use Laminas\Db\Adapter\Driver\DriverInterface;
use Laminas\Db\Adapter\Exception\RuntimeException;
use Laminas\Db\Adapter\Mysql\Adapter;
use Laminas\Db\Adapter\Platform\PlatformInterface;
use Laminas\Db\Adapter\Profiler\ProfilerInterface;
Expand All @@ -19,8 +20,19 @@ public function __invoke(ContainerInterface $container): AdapterInterface
{
/** @var AdapterManager $adapterManager */
$adapterManager = $container->get(AdapterManager::class);
/** @var array $config */
$config = $container->get('config');
if (! isset($config['db']['driver'])) {
throw new RuntimeException('Database driver configuration is missing.');
}
if (! $adapterManager->has($config['db']['driver'])) {
throw new RuntimeException(sprintf(
'Database driver "%s" is not registered in the adapter manager.',
$config['db']['driver']
));
}
return new Adapter(
$adapterManager->get(DriverInterface::class),
$adapterManager->get($config['db']['driver']),
$adapterManager->get(PlatformInterface::class),
$adapterManager->get(ResultSetInterface::class),
$adapterManager->get(ProfilerInterface::class)
Expand Down
35 changes: 26 additions & 9 deletions src/Container/AdapterManagerDelegator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
namespace Laminas\Db\Adapter\Mysql\Container;

use Laminas\Db\Adapter\AdapterInterface;
use Laminas\Db\Adapter\Driver\ConnectionInterface;
use Laminas\Db\Adapter\Driver\DriverInterface;
use Laminas\Db\Adapter\Driver\ResultInterface;
use Laminas\Db\Adapter\Driver\PdoDriverInterface;
use Laminas\Db\Adapter\Driver\Pdo\Result;
use Laminas\Db\Adapter\Driver\Pdo\Statement as PdoStatement;
use Laminas\Db\Adapter\Mysql\Driver;
use Laminas\Db\Adapter\Platform\PlatformInterface;
use Laminas\Db\Adapter\Profiler;
use Laminas\Db\Container\AdapterManager;
Expand All @@ -27,17 +29,32 @@ public function __invoke(
$adapterManager = $callback();
$adapterManager->configure([
'aliases' => [
'MySqli' => Driver\Mysqli\Mysqli::class,
'MySQLi' => Driver\Mysqli\Mysqli::class,
'mysqli' => Driver\Mysqli\Mysqli::class,
'Pdo_Mysql' => Driver\Pdo\Pdo::class,
'pdo_mysql' => Driver\Pdo\Pdo::class,
'pdomysql' => Driver\Pdo\Pdo::class,
'pdodriver' => Driver\Pdo\Pdo::class,
'pdo' => Driver\Pdo\Pdo::class,
DriverInterface::class => Driver\Mysqli\Mysqli::class,
PdoDriverInterface::class => Driver\Pdo\Pdo::class,
Profiler\ProfilerInterface::class => Profiler\Profiler::class,
ResultSet\ResultSetInterface::class => ResultSet\ResultSet::class,
],
'factories' => [
AdapterInterface::class => AdapterFactory::class,
ConnectionInterface::class => ConnectionInterfaceFactory::class,
DriverInterface::class => DriverInterfaceFactory::class,
PlatformInterface::class => PlatformInterfaceFactory::class,
Profiler\Profiler::class => InvokableFactory::class,
ResultInterface::class => ResultInterfaceFactory::class,
ResultSet\ResultSet::class => InvokableFactory::class,
AdapterInterface::class => AdapterFactory::class,
Driver\Mysqli\Mysqli::class => MysqliDriverFactory::class,
Driver\Mysqli\Connection::class => MysqliConnectionFactory::class,
Driver\Mysqli\Result::class => MysqliResultFactory::class,
Driver\Mysqli\Statement::class => MysqliStatementFactory::class,
Driver\Pdo\Pdo::class => PdoDriverFactory::class,
Driver\Pdo\Connection::class => PdoConnectionFactory::class,
Result::class => PdoResultFactory::class,
PdoStatement::class => PdoStatementFactory::class,
PlatformInterface::class => PlatformInterfaceFactory::class,
Profiler\Profiler::class => InvokableFactory::class,
ResultSet\ResultSet::class => InvokableFactory::class,
],
]);

Expand Down
20 changes: 0 additions & 20 deletions src/Container/ConnectionInterfaceFactory.php

This file was deleted.

6 changes: 3 additions & 3 deletions src/Container/InterfaceFactoryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ private function getDriver(AdapterManager $adapterManager): DriverInterface
$adapterManager->get(ConnectionInterface::class)
);
}
return new Driver\Mysqli\Mysqli(
$adapterManager->get(ConnectionInterface::class)
);
// return new Driver\Mysqli\Mysqli(
// $adapterManager->get(ConnectionInterface::class)
// );
}

private function getResult(AdapterManager $adapterManager): ResultInterface
Expand Down
19 changes: 19 additions & 0 deletions src/Container/MysqliConnectionFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Laminas\Db\Adapter\Mysql\Container;

use Laminas\Db\Adapter\Driver\ConnectionInterface;
use Laminas\Db\Adapter\Mysql\Driver\Mysqli\Connection;
use Psr\Container\ContainerInterface;

final class MysqliConnectionFactory
{
public function __invoke(ContainerInterface $container): ConnectionInterface
{
$dbConfig = $container->get('config')['db']['connection'] ?? [];

return new Connection($dbConfig);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@
namespace Laminas\Db\Adapter\Mysql\Container;

use Laminas\Db\Adapter\Driver\DriverInterface;
use Laminas\Db\Adapter\Mysql\Driver\Mysqli;
use Laminas\Db\Container\AdapterManager;
use Psr\Container\ContainerInterface;

final class DriverInterfaceFactory
final class MysqliDriverFactory
{
use InterfaceFactoryTrait;

public function __invoke(ContainerInterface $container): DriverInterface
{
/** @var AdapterManager $adapterManager */
$adapterManager = $container->get(AdapterManager::class);
return $this->getDriver($adapterManager);
$options = $container->get('config')['db']['options'] ?? [];
return new Mysqli\Mysqli(
$adapterManager->get(Mysqli\Connection::class),
$adapterManager->get(Mysqli\Statement::class),
$adapterManager->get(Mysqli\Result::class),
$options
);
}
}
17 changes: 17 additions & 0 deletions src/Container/MysqliResultFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Laminas\Db\Adapter\Mysql\Container;

use Laminas\Db\Adapter\Driver\ResultInterface;
use Laminas\Db\Adapter\Mysql\Driver\Mysqli\Result;
use Psr\Container\ContainerInterface;

final class MysqliResultFactory
{
public function __invoke(ContainerInterface $container): ResultInterface&Result
{
return new Result();
}
}
18 changes: 18 additions & 0 deletions src/Container/MysqliStatementFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Laminas\Db\Adapter\Mysql\Container;

use Laminas\Db\Adapter\Driver\StatementInterface;
use Laminas\Db\Adapter\Mysql\Driver\Mysqli\Statement;
use Psr\Container\ContainerInterface;

final class MysqliStatementFactory
{
public function __invoke(ContainerInterface $container): StatementInterface
{
$bufferResults = $container->get('config')['db']['options']['buffer_results'] ?? false;
return new Statement($bufferResults);
}
}
17 changes: 17 additions & 0 deletions src/Container/PdoConnectionFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Laminas\Db\Adapter\Mysql\Container;

use Laminas\Db\Adapter\Driver\ConnectionInterface;
use Laminas\Db\Adapter\Mysql\Driver\Pdo\Connection;
use Psr\Container\ContainerInterface;

final class PdoConnectionFactory
{
public function __invoke(ContainerInterface $container): ConnectionInterface {
$dbConfig = $container->get('config')['db']['connection'] ?? [];
return new Connection($dbConfig);
}
}
10 changes: 10 additions & 0 deletions src/Container/PdoDriverFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Laminas\Db\Adapter\Mysql\Container;

final class PdoDriverFactory
{

}
10 changes: 10 additions & 0 deletions src/Container/PdoResultFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Laminas\Db\Adapter\Mysql\Container;

final class PdoResultFactory
{

}
10 changes: 10 additions & 0 deletions src/Container/PdoStatementFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Laminas\Db\Adapter\Mysql\Container;

final class PdoStatementFactory
{

}
21 changes: 0 additions & 21 deletions src/Container/ResultInterfaceFactory.php

This file was deleted.

Loading
Loading