phoenix icon indicating copy to clipboard operation
phoenix copied to clipboard

Extract the static methods of the Type class into a TypeRegistry service

Open ruudk opened this issue 1 month ago • 1 comments

Feature Request

Copied from:

  • https://github.com/doctrine/mongodb-odm/issues/2818

In order to have distinct types per EntityManager instance, the static methods of the Type class must move to a TypeRegistry service class. This design is inspired by the Doctrine\DBAL\Types\TypeRegistry class.

  • Introduce the TypeRegistry
  • Inject the TypeRegistry instance everywhere the static method of the Type class are used
  • Make the constructor of Type public and non-final to allow injecting dependencies or configuration into the type instances
  • A similar change has been discussed in https://github.com/doctrine/dbal/pull/6705#pullrequestreview-2599239196

Use case

I want to create a custom type, that needs some services from the container.

final class JsonSerializableType extends JsonType
{
    public function __construct(
        private readonly DbalJsonTypeSerializer $serializer,
    ) {}

    // ...
}

Currently, I have to resort on a "ugly" boot() hack in the kernel, to use it:

public function boot() : void
{
    parent::boot();

    Type::getTypeRegistry()->register(
        $name,
        new JsonSerializableType($this->container->get(DbalJsonTypeSerializer::class)),
    );
}

ruudk avatar Nov 13 '25 11:11 ruudk

@greg0ire @derrabus Tagging you both, since you were also involved in https://github.com/doctrine/dbal/pull/6705. I'm happy to do the work, if you can guide me on the how and what!

ruudk avatar Nov 13 '25 12:11 ruudk