Skip to content

Commit df0b1dd

Browse files
authored
Merge pull request #127 from tyrsson/fix-ambigious-factory-exception-message
tweaks to factory exception message
2 parents e28a824 + ca63f19 commit df0b1dd

File tree

4 files changed

+34
-52
lines changed

4 files changed

+34
-52
lines changed

composer.lock

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

src/ConfigProvider.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,11 @@
77
final class ConfigProvider
88
{
99
public const NAMED_ADAPTER_KEY = 'adapters';
10-
public function __invoke(): array
11-
{
12-
return [
13-
'dependencies' => $this->getDependencies(),
14-
Adapter\AdapterInterface::class => $this->getConfig(),
15-
];
16-
}
1710

18-
public function getConfig(): array
11+
public function __invoke(): array
1912
{
20-
// supported configuration structure
2113
return [
22-
// Adapter\Adapter::class => [],
23-
// Adapter\AdapterInterface::class => [],
24-
// self::NAMED_ADAPTER_KEY => [
25-
// Adapter\Adapter::class => [],
26-
// Adapter\AdapterInterface::class => [],
27-
// 'Custom\Name' => [],
28-
// ],
14+
'dependencies' => $this->getDependencies(),
2915
];
3016
}
3117

src/Container/AdapterInterfaceFactory.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function __invoke(
2929
'Container is missing a config service'
3030
);
3131
}
32+
3233
$config = $container->get('config') ?? [];
3334
$adapterConfig = $config[AdapterInterface::class] ?? $config[Adapter::class] ?? [];
3435

@@ -43,14 +44,6 @@ public function __invoke(
4344
/** @var class-string<DriverInterface>|class-string<PdoDriverInterface>|null $driverClass */
4445
$driverClass = $adapterConfig['driver'] ?? null;
4546

46-
if ($driverClass === null || ! $container->has($driverClass)) {
47-
throw ContainerException::forService(
48-
AdapterInterface::class,
49-
self::class,
50-
'Invalid or missing driver provided for ' . $requestedName
51-
);
52-
}
53-
5447
/** @var DriverInterface|PdoDriverInterface $driver */
5548
$driver = $container->build($driverClass, $adapterConfig);
5649

test/unit/ConfigProviderTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ class ConfigProviderTest extends TestCase
2121
* }
2222
* */
2323
private array $config = [
24-
Adapter\AdapterInterface::class => [],
25-
'dependencies' => [
24+
'dependencies' => [
2625
'abstract_factories' => [
2726
Container\AbstractAdapterInterfaceFactory::class,
2827
],

0 commit comments

Comments
 (0)