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
108 changes: 62 additions & 46 deletions composer.lock

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

16 changes: 8 additions & 8 deletions src/Container/MetadataInterfaceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
namespace PhpDb\Sqlite\Container;

use PhpDb\Adapter\AdapterInterface;
use PhpDb\Adapter\SchemaAwareInterface;
use PhpDb\Metadata\MetadataInterface;
use PhpDb\Sqlite\Metadata;
use Psr\Container\ContainerInterface;

final class MetadataInterfaceFactory
{
public function __invoke(ContainerInterface $container): MetadataInterface&Metadata\Source
{
/** @var AdapterInterface&SchemaAwareInterface $adapter */
$adapter = $container->get(AdapterInterface::class);
public const ADAPTER_SERVICE_NAME = 'adapter_service_name';
public function __invoke(
ContainerInterface $container,
string $requestedName,
?array $options = null
): MetadataInterface&Metadata\Source {
$adapterServiceName = $options[self::ADAPTER_SERVICE_NAME] ?? AdapterInterface::class;

return new Metadata\Source(
$adapter
);
return new Metadata\Source($container->get($adapterServiceName));
}
}
30 changes: 17 additions & 13 deletions src/Container/PdoConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,28 @@

namespace PhpDb\Sqlite\Container;

use PhpDb\Adapter\AdapterInterface;
use PhpDb\Adapter\Driver\ConnectionInterface;
use PhpDb\Adapter\Driver\PdoConnectionInterface;
use PhpDb\Adapter\Exception\InvalidConnectionParametersException;
use PhpDb\Sqlite\Pdo\Connection;
use Psr\Container\ContainerInterface;

use function is_array;

final class PdoConnectionFactory
{
public function __invoke(ContainerInterface $container): ConnectionInterface&Connection
{
/** @var array $config */
$config = $container->get('config');

/** @var array $dbConfig */
$dbConfig = $config[AdapterInterface::class] ?? [];

/** @var array $connectionConfig */
$connectionConfig = $dbConfig['connection'] ?? [];
public function __invoke(
ContainerInterface $container,
string $requestedName,
?array $options = null
): PdoConnectionInterface&Connection {
$conn = $options['connection'] ?? [];
if (! is_array($conn) || $conn === []) {
throw new InvalidConnectionParametersException(
'Connection configuration must be an array of parameters passed via $options["connection"]',
$conn
);
}

return new Connection($connectionConfig);
return new Connection($conn);
}
}
10 changes: 1 addition & 9 deletions src/Container/PdoDriverInterfaceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,10 @@ public function __invoke(
string $requestedName,
?array $options = null
): PdoDriverInterface&Pdo\Driver {
// if (! $container->has('config')) {
// throw ContainerException::forService(
// Pdo\Driver::class,
// self::class,
// 'Container is missing config service'
// );
// }

/** @var Pdo\Connection $connectionInstance */
$connectionInstance = $container->build(
Pdo\Connection::class,
['connection' => $options['connection'] ?? []]
$options
);

/** @var ResultInterface&Result $resultInstance */
Expand Down
Loading