diff options
author | Joas Schilling <coding@schilljs.com> | 2023-09-25 15:33:40 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2023-09-25 15:54:21 +0200 |
commit | 0956b493b6394a6ea3c748fa5dd0910bc697ba8a (patch) | |
tree | be06005539d5f7d38fb36352578fd841506ee304 /lib/private/Accounts | |
parent | 5092278b0f4bf1905fe08d51ad329682b6e8f410 (diff) | |
download | nextcloud-server-0956b493b6394a6ea3c748fa5dd0910bc697ba8a.tar.gz nextcloud-server-0956b493b6394a6ea3c748fa5dd0910bc697ba8a.zip |
fix(phonenumber): Use the newly introduced API to limit 3rdparty lib usage
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private/Accounts')
-rw-r--r-- | lib/private/Accounts/AccountManager.php | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/lib/private/Accounts/AccountManager.php b/lib/private/Accounts/AccountManager.php index 9865438161b..3e33e783635 100644 --- a/lib/private/Accounts/AccountManager.php +++ b/lib/private/Accounts/AccountManager.php @@ -37,9 +37,6 @@ namespace OC\Accounts; use Exception; use InvalidArgumentException; -use libphonenumber\NumberParseException; -use libphonenumber\PhoneNumberFormat; -use libphonenumber\PhoneNumberUtil; use OC\Profile\TProfileHelper; use OCP\Accounts\UserUpdatedEvent; use OCP\Cache\CappedMemoryCache; @@ -56,6 +53,7 @@ use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IDBConnection; use OCP\IL10N; +use OCP\IPhoneNumberUtil; use OCP\IURLGenerator; use OCP\IUser; use OCP\L10N\IFactory; @@ -119,6 +117,7 @@ class AccountManager implements IAccountManager { private IFactory $l10nFactory, private IURLGenerator $urlGenerator, private ICrypto $crypto, + private IPhoneNumberUtil $phoneNumberUtil, ) { $this->internalCache = new CappedMemoryCache(); } @@ -139,13 +138,9 @@ class AccountManager implements IAccountManager { $defaultRegion = 'EN'; } - $phoneUtil = PhoneNumberUtil::getInstance(); - try { - $phoneNumber = $phoneUtil->parse($input, $defaultRegion); - if ($phoneUtil->isValidNumber($phoneNumber)) { - return $phoneUtil->format($phoneNumber, PhoneNumberFormat::E164); - } - } catch (NumberParseException $e) { + $phoneNumber = $this->phoneNumberUtil->convertToStandardFormat($input, $defaultRegion); + if ($phoneNumber !== null) { + return $phoneNumber; } throw new InvalidArgumentException(self::PROPERTY_PHONE); |