Add #[AsDbalType] attribute#2197
Conversation
e26bfe1 to
ea214eb
Compare
|
@stof is it ok for you? |
|
I think this PR belongs more into the symfony/doctrine-bridge and there is already a PR for this: symfony/symfony#63774 |
AFAIK, the bridge aims to do a bridge between a Symfony component and Doctrine, but this feature is not related to a Symfony component, so it should belongs to the bundle IMHO |
|
I’m not fully convinced this should live in the bundle. According to the Symfony docs, DoctrineBridge is meant to “provide integration for Doctrine with Symfony components”, while DoctrineBundle mainly handles configuration and wiring. This change feels more like integration logic (how Symfony registers and discovers Doctrine types) rather than something that should be driven by bundle configuration. We already keep things like Doctrine types and Symfony specific behavior in the Bridge, so moving the registration logic there would keep responsibilities more clearly separated and consistent with existing patterns. Otherwise we risk spreading behavior across both layers, which makes it harder to reason about and reuse outside of a full DoctrineBundle setup. |
I agree with that, but there is no component involved here
Types you mention are Symfony component related types (Uid, Clock,...) |
|
@greg0ire What do you think about that ? |
|
I agree with you, and furthermore, there are other attributes already: https://github.com/doctrine/DoctrineBundle/tree/3.2.x/src/Attribute |
ea214eb to
7cea86e
Compare
@greg0ire Documentation added ;) |
ccf6386 to
e92c0b5
Compare
e92c0b5 to
ef724c7
Compare
|
@greg0ire commits squashed 👍 |
|
I'm working on this topic using a
I want to give a more advanced review before we introduce a solution that will be updated. In any case, I think it is useful to have an attribute like |
f44079e to
51f8380
Compare
@GromNaN I love the idea of being able to configure types per connection and having them potentially registered as services. The migration path might be long and could be split into several small steps :
WDYT ? I would be happy to help. In the meantime, I reworked my first implementation to make the attribute name optional, and I renamed the attribute as proposed. |
SenseException
left a comment
There was a problem hiding this comment.
I believe 3.2.0 isn't the correct branch anymore because this is a new feature.
#[AsDatabaseType] attribute
8b4961e to
ad0ae11
Compare
#[AsDatabaseType] attribute#[AsDatabaseType] attribute
|
@GromNaN Is it good for you ? Can I squash my commits ? |
ef4f3c2 to
4f98475
Compare
|
@GromNaN Commits squashed. Many thanks ;) |
9468a0a to
7754d0b
Compare
7754d0b to
f048045
Compare
|
@greg0ire @SenseException is it still Ok for you? |
|
Thank you @syl20b |
Description
This PR add a new
#[AsDbalType]attribute to automatically register the related class as a DBAL type.Problem Solved
Currently, to register a custom DBAL type, it must be manually declared in the Doctrine configuration file:
This approach is verbose and requires the developer to manage configuration in addition to the type class itself.
Feature Added
The addition of the
#[AsDbalType]attribute allows the application to automatically detect and register any class that uses this attribute.Concrete Usage Example
Here is how you can register a custom type directly via the attribute, without touching the YAML configuration:
1. Creating the Custom Type
2. Usage in an Entity
You can then use this type directly in your entities:
Advantages
doctrine.yamlfor every new custom type.