doctrine / DoctrineBundle

Symfony Bundle for Doctrine ORM and DBAL
https://www.doctrine-project.org/projects/doctrine-bundle.html
MIT License
4.72k stars 454 forks source link

Enable to set custom TypedFieldMapper; #1802

Closed jifer closed 6 months ago

jifer commented 6 months ago

This PR add typed_field_mapper option allowing to override or set custom TypedFieldMapper as described in ORM documentation. This option allows auto detection of doctrine types based on PHP typed properties.

https://www.doctrine-project.org/projects/doctrine-orm/en/3.1/reference/typedfieldmapper.html

\Doctrine\ORM\Configuration::getTypedFieldMapper() return null as default and \Doctrine\ORM\Mapping\ClassMetadataInfo instance is created by providing null or TypedFieldMapper. If null \Doctrine\ORM\Mapping\DefaultTypedFieldMapper is created. This why i set it as default under typed_field_mapper option.

public function __construct($entityName, ?NamingStrategy $namingStrategy = null, ?TypedFieldMapper $typedFieldMapper = null)
{
   // [..]
    $this->typedFieldMapper = $typedFieldMapper ?? new DefaultTypedFieldMapper();
}
ostrolucky commented 6 months ago

You need to adjust xsd schema too

jifer commented 6 months ago

Thank you. I see I missed few things, including DI test. That's my first try here so apologies if I did something wrong.

jifer commented 6 months ago

@ostrolucky I'm not sure if there is something more I should update? Thank you in advance.