UPSTREAM BASELINE: nextcloud/spreed v22.0.12 (без изменений)
Type checking / changes (push) Has been cancelled
Type checking / test (push) Has been cancelled
Type checking / typescript-summary (push) Has been cancelled
Node tests / changes (push) Has been cancelled
Node tests / test (push) Has been cancelled
Node tests / test-summary (push) Has been cancelled
Type checking / changes (push) Has been cancelled
Type checking / test (push) Has been cancelled
Type checking / typescript-summary (push) Has been cancelled
Node tests / changes (push) Has been cancelled
Node tests / test (push) Has been cancelled
Node tests / test-summary (push) Has been cancelled
Источник: https://github.com/nextcloud/spreed/archive/refs/tags/v22.0.12.tar.gz С этого коммита ветка официального Nextcloud Talk отрезана (решение владельца 2026-07-06). Все дальнейшие изменения — только наши; версии релизов: 22.0.12-f7.N.
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Talk\Service;
|
||||
|
||||
use OCP\IConfig;
|
||||
use OCP\IPhoneNumberUtil;
|
||||
|
||||
class PhoneNumberValidation {
|
||||
|
||||
public function __construct(
|
||||
protected IPhoneNumberUtil $phoneNumberUtil,
|
||||
protected IConfig $config,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate input as a phone number
|
||||
*
|
||||
* - Local number: allow
|
||||
* - International number
|
||||
* a. If valid, strip + and allow
|
||||
* b. If invalid, throw
|
||||
* @throws \InvalidArgumentException When the number is invalid
|
||||
*/
|
||||
public function validateNumber(string $phoneNumber): string {
|
||||
|
||||
if (
|
||||
// Not an internation number
|
||||
!str_starts_with($phoneNumber, '0')
|
||||
// And matches a local number or dial-through
|
||||
&& preg_match('/^[0-9]{1,20}$/', $phoneNumber)
|
||||
) {
|
||||
return $phoneNumber;
|
||||
}
|
||||
|
||||
$defaultRegion = $this->config->getSystemValueString('default_phone_region') ?: null;
|
||||
$standardPhoneNumber = $this->phoneNumberUtil->convertToStandardFormat($phoneNumber, $defaultRegion);
|
||||
|
||||
if ($standardPhoneNumber === null) {
|
||||
throw new \InvalidArgumentException();
|
||||
}
|
||||
|
||||
if (str_starts_with($standardPhoneNumber, '+')) {
|
||||
return substr($standardPhoneNumber, 1);
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user