diff --git a/composer.json b/composer.json index e0370d6..68a801b 100755 --- a/composer.json +++ b/composer.json @@ -1,6 +1,7 @@ { "require": { "ingenerator/tokenista": "^1.1", - "ajani/flash-message": "^2.0" + "ajani/flash-message": "^2.0", + "giggsey/libphonenumber-for-php": "^8.10" } } diff --git a/controllers/internals/Contact.php b/controllers/internals/Contact.php index 9e7f02e..9f3af67 100755 --- a/controllers/internals/Contact.php +++ b/controllers/internals/Contact.php @@ -123,7 +123,7 @@ namespace controllers\internals; 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; } diff --git a/controllers/internals/Tool.php b/controllers/internals/Tool.php index 1252ace..bccd1f3 100755 --- a/controllers/internals/Tool.php +++ b/controllers/internals/Tool.php @@ -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 */ - 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); } /**