Skip to content

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

@ruudk

Description

@ruudk

Feature Request

Copied from:

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 Remove final constructor for Type dbal#6705 (review)

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)),
    );
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions