Skip to content

Commit 3107b1a

Browse files
committed
use FQCN as default type name
1 parent af044b8 commit 3107b1a

2 files changed

Lines changed: 4 additions & 12 deletions

File tree

src/DependencyInjection/Compiler/RegisterDbalTypePass.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Symfony\Component\DependencyInjection\ContainerBuilder;
1313
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1414

15-
use function array_key_exists;
1615
use function is_subclass_of;
1716
use function method_exists;
1817
use function sprintf;
@@ -50,10 +49,6 @@ public function process(ContainerBuilder $container): void
5049

5150
foreach ($this->findTaggedResourceIds($container) as $id => $tags) {
5251
foreach ($tags as $tag) {
53-
if (! array_key_exists('name', $tag)) {
54-
throw new InvalidArgumentException(sprintf('The "name" attribute is mandatory for the "doctrine.dbal.type" tag on the "%s" type.', $id));
55-
}
56-
5752
$class = $container->getDefinition($id)->getClass();
5853
if (! $class) {
5954
throw new InvalidArgumentException(sprintf('The definition of "%s" must define its class.', $id));
@@ -63,7 +58,7 @@ public function process(ContainerBuilder $container): void
6358
throw new InvalidArgumentException(sprintf('The "%s" class must extends "%s".', $class, Type::class));
6459
}
6560

66-
$types[$tag['name']] = ['class' => $class];
61+
$types[$tag['name'] ?? $class] = ['class' => $class];
6762
}
6863
}
6964

tests/DependencyInjection/Compiler/RegisterDbalTypePassTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testTaggedTypeAreAdded(): void
3131
self::assertSame(['bar' => ['class' => BarType::class]], $container->getParameter('doctrine.dbal.connection_factory.types'));
3232
}
3333

34-
public function testTagMustHaveANameAttribute(): void
34+
public function testUseClassnameAsTypeNameIfNotDefined(): void
3535
{
3636
$container = new ContainerBuilder();
3737
$container->addCompilerPass(new RegisterDbalTypePass());
@@ -42,12 +42,9 @@ public function testTagMustHaveANameAttribute(): void
4242
->addTag('doctrine.dbal.type')
4343
->addTag('container.excluded');
4444

45-
$this->expectException(InvalidArgumentException::class);
46-
$this->expectExceptionMessage(
47-
sprintf('The "name" attribute is mandatory for the "doctrine.dbal.type" tag on the "%s" type.', BarType::class),
48-
);
49-
5045
$container->compile();
46+
47+
self::assertSame([BarType::class => ['class' => BarType::class]], $container->getParameter('doctrine.dbal.connection_factory.types'));
5148
}
5249

5350
public function testTypeMustBeASubclassOfTheDbalBaseType(): void

0 commit comments

Comments
 (0)