phone-number-bundle
phone-number-bundle copied to clipboard
Extensions Are Silently Dropped
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.
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?
@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.
Yeah, I've just done the same thing locally.
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?