Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 15 additions & 0 deletions src/Attribute/AsDoctrineType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Doctrine\Bundle\DoctrineBundle\Attribute;

use Attribute;

#[Attribute(Attribute::TARGET_CLASS)]
final readonly class AsDoctrineType
{
public function __construct(public string $name)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/** @internal */
final class RegisterAsDoctrineTypeAttributePass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
$types = $container->getParameter('doctrine.dbal.connection_factory.types');

foreach ($container->findTaggedServiceIds('doctrine.dbal.type') as $id => $tags) {
$types[$tags[0]['name']] = ['class' => $container->getDefinition($id)->getClass()];
}

$container->setParameter('doctrine.dbal.connection_factory.types', $types);
}
}
7 changes: 7 additions & 0 deletions src/DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\Bundle\DoctrineBundle\DependencyInjection;

use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineType;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsEntityListener;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsMiddleware;
use Doctrine\Bundle\DoctrineBundle\CacheWarmer\DoctrineMetadataCacheWarmer;
Expand Down Expand Up @@ -550,6 +551,12 @@ private function dbalLoad(array $config, ContainerBuilder $container): void
$this->loadDbalConnection($name, $connection, $container);
}

$container->registerAttributeForAutoconfiguration(AsDoctrineType::class, static function (ChildDefinition $definition, AsDoctrineType $type): void {
$definition->addTag('doctrine.dbal.type', [
'name' => $type->name,
]);
});

$container->registerForAutoconfiguration(MiddlewareInterface::class)->addTag('doctrine.middleware');

$container->registerAttributeForAutoconfiguration(AsMiddleware::class, static function (ChildDefinition $definition, AsMiddleware $attribute): void {
Expand Down
2 changes: 2 additions & 0 deletions src/DoctrineBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\EntityListenerPass;
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\IdGeneratorPass;
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\MiddlewaresPass;
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\RegisterAsDoctrineTypeAttributePass;
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\RemoveLoggingMiddlewarePass;
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\RemoveProfilerControllerPass;
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\ServiceRepositoryCompilerPass;
Expand Down Expand Up @@ -68,6 +69,7 @@ public function process(ContainerBuilder $container): void
$container->addCompilerPass(new RemoveLoggingMiddlewarePass());
$container->addCompilerPass(new MiddlewaresPass());
$container->addCompilerPass(new RegisterUidTypePass());
$container->addCompilerPass(new RegisterAsDoctrineTypeAttributePass());

if (! class_exists(RegisterDatePointTypePass::class)) {
return;
Expand Down