misd-service-development / phone-number-bundle

Integrates libphonenumber into your Symfony2-Symfony4 application
459 stars 143 forks source link

Extensions Are Silently Dropped #183

Open kiler129 opened 6 years ago

kiler129 commented 6 years ago

Problem

While working with phone numbers I discovered that phone numbers aren't handled properly when they contain extension. This is related to https://github.com/giggsey/libphonenumber-for-php/issues/255, since PhoneNumberType internally calls PhoneNumberUtil::format() while saving and PhoneNumberUtil::parse() while reading.

Solution

Maybe a better way would be to serialize and unserialize the object instead to prevent loosing data, since PhoneNumber intentionally implements \Serializable. Of course at this point it has to be done as a separate DBAL type to prevent BC issues with old data saved in DB.

I can prepare patch if you like, however I'm not sure is that what you want to do.

Workaround

Currently the easiest workaround for the issue while using anemic entities is to use two fields in entity, say phone & phoneExt and make getPhone() add extension to the object from phoneExt() and setPhone() to extract extension to a separate field.

gnat42 commented 5 years ago

Why not store the PhoneNumberFormat::RFC3966 ? This stores the extension as well. Is there data it loses compared to E164? I'm wondering if we could even configure the doctrine type to allow us to pick the DB format?

kiler129 commented 5 years ago

@gnat42 Mostly useless overhead of tel:. However we actually did that and we store RFC-3966 format with custom doctrine type. We can strip tel: on conversion, but we don't do that to make stuff more standarized.

gnat42 commented 5 years ago

Yeah, I've just done the same thing locally.

webmasterMeyers commented 4 years ago

I have also discovered this issue. This is on a brand new setup, so BC is not an issue.

when you say to use "setPhone() to extract extension to a separate field." do you mean in the entity? Do you have a code example of the getter and setter methods you use for this?