fix format number

This commit is contained in:
osaajani 2019-11-10 01:17:28 +01:00
parent 4fd36ad820
commit f87aebb20c
3 changed files with 7 additions and 4 deletions

View File

@ -1,6 +1,7 @@
{ {
"require": { "require": {
"ingenerator/tokenista": "^1.1", "ingenerator/tokenista": "^1.1",
"ajani/flash-message": "^2.0" "ajani/flash-message": "^2.0",
"giggsey/libphonenumber-for-php": "^8.10"
} }
} }

View File

@ -123,7 +123,7 @@ namespace controllers\internals;
return $result; return $result;
} }
$this->internal_event->create('CONTACT_ADD', 'Ajout contact : '.$name.' ('.\controllers\internals\Tool::phone_add_space($number).')'); $this->internal_event->create('CONTACT_ADD', 'Ajout contact : '.$name.' ('.\controllers\internals\Tool::phone_format($number).')');
return $result; return $result;
} }

View File

@ -39,9 +39,11 @@ namespace controllers\internals;
* *
* @return mixed : Si le numéro est bien un numéro de téléphone, on retourne le numéro parsé. Sinon, on retourne faux * @return mixed : Si le numéro est bien un numéro de téléphone, on retourne le numéro parsé. Sinon, on retourne faux
*/ */
public static function phone_add_space($number) public static function phone_format($number)
{ {
return preg_replace('#(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})#', '$1 $2 $3 $4 $5', $number); $phone_number_util = \libphonenumber\PhoneNumberUtil::getInstance();
$phone_number_o = $phone_number_util->parse($number, null);
return $phone_number_util->format($phone_number_o, \libphonenumber\PhoneNumberFormat::INTERNATIONAL);
} }
/** /**