validation-bugsnag-email
This commit is contained in:
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace Propaganistas\LaravelPhone\Exceptions;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class InvalidParameterException extends \Exception
|
||||
{
|
||||
/**
|
||||
|
@@ -13,9 +13,8 @@ use libphonenumber\NumberParseException as libNumberParseException;
|
||||
use libphonenumber\PhoneNumberFormat;
|
||||
use libphonenumber\PhoneNumberType;
|
||||
use libphonenumber\PhoneNumberUtil;
|
||||
use Propaganistas\LaravelPhone\Exceptions\InvalidParameterException;
|
||||
use Propaganistas\LaravelPhone\Exceptions\NumberFormatException;
|
||||
use Propaganistas\LaravelPhone\Exceptions\CountryCodeException;
|
||||
use Propaganistas\LaravelPhone\Exceptions\NumberFormatException;
|
||||
use Propaganistas\LaravelPhone\Exceptions\NumberParseException;
|
||||
use Propaganistas\LaravelPhone\Traits\ParsesCountries;
|
||||
use Propaganistas\LaravelPhone\Traits\ParsesFormats;
|
||||
@@ -273,7 +272,9 @@ class PhoneNumber implements Jsonable, JsonSerializable, Serializable
|
||||
}
|
||||
}
|
||||
|
||||
if ($countries = array_filter($countries)) {
|
||||
$countries = array_filter($countries);
|
||||
|
||||
if (! empty($countries)) {
|
||||
throw NumberParseException::countryMismatch($this->number, $countries);
|
||||
}
|
||||
|
||||
@@ -376,7 +377,15 @@ class PhoneNumber implements Jsonable, JsonSerializable, Serializable
|
||||
*/
|
||||
public function numberLooksInternational()
|
||||
{
|
||||
return Str::startsWith($this->number, '+');
|
||||
if (empty($this->number)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Str::startsWith($this->number, '+')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return strpos($this->number, '+', 2) && static::isValidCountryCode(Str::substr($this->number, 0, 2));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -24,7 +24,7 @@ class PhoneServiceProvider extends ServiceProvider
|
||||
|
||||
$this->app->alias('libphonenumber', PhoneNumberUtil::class);
|
||||
|
||||
$this->app->afterResolving('validator', static function (Factory $validator) {
|
||||
$this->callAfterResolving('validator', function (Factory $validator) {
|
||||
$validator->extendDependent('phone', Validation\Phone::class . '@validate');
|
||||
});
|
||||
|
||||
|
@@ -3,13 +3,12 @@
|
||||
namespace Propaganistas\LaravelPhone\Rules;
|
||||
|
||||
use libphonenumber\PhoneNumberType;
|
||||
use Propaganistas\LaravelPhone\Traits\ParsesCountries;
|
||||
use Propaganistas\LaravelPhone\Traits\ParsesTypes;
|
||||
|
||||
class Phone
|
||||
{
|
||||
use ParsesTypes;
|
||||
|
||||
|
||||
/**
|
||||
* The provided phone countries.
|
||||
*
|
||||
|
@@ -3,7 +3,7 @@
|
||||
namespace Propaganistas\LaravelPhone\Traits;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use League\ISO3166\ISO3166;
|
||||
use libphonenumber\PhoneNumberUtil;
|
||||
|
||||
trait ParsesCountries
|
||||
{
|
||||
@@ -15,15 +15,7 @@ trait ParsesCountries
|
||||
*/
|
||||
public static function isValidCountryCode($country)
|
||||
{
|
||||
$iso3166 = new ISO3166;
|
||||
|
||||
try {
|
||||
$iso3166->alpha2($country);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
return in_array(strtoupper($country), array_map('strtoupper', PhoneNumberUtil::getInstance()->getSupportedRegions()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,15 +27,14 @@ trait ParsesCountries
|
||||
protected function parseCountries($countries)
|
||||
{
|
||||
return Collection::make(is_array($countries) ? $countries : func_get_args())
|
||||
->reject(function ($value) {
|
||||
/** @phpstan-ignore-next-line */
|
||||
return is_null($value);
|
||||
})
|
||||
->map(function ($country) {
|
||||
return strtoupper($country);
|
||||
})
|
||||
->filter(function ($value) {
|
||||
return static::isValidCountryCode($value);
|
||||
})->toArray();
|
||||
->reject(function ($value) {
|
||||
/** @phpstan-ignore-next-line */
|
||||
return is_null($value);
|
||||
})
|
||||
->filter(function ($value) {
|
||||
return static::isValidCountryCode($value);
|
||||
})->map(function ($value) {
|
||||
return strtoupper($value);
|
||||
})->toArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -4,9 +4,9 @@ namespace Propaganistas\LaravelPhone\Validation;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use libphonenumber\NumberParseException;
|
||||
use libphonenumber\PhoneNumberUtil;
|
||||
use Propaganistas\LaravelPhone\Exceptions\InvalidParameterException;
|
||||
use libphonenumber\NumberParseException;
|
||||
use Propaganistas\LaravelPhone\PhoneNumber;
|
||||
use Propaganistas\LaravelPhone\Traits\ParsesCountries;
|
||||
use Propaganistas\LaravelPhone\Traits\ParsesTypes;
|
||||
@@ -122,7 +122,7 @@ class Phone
|
||||
$parameters[] = $inputCountry;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$parameters = array_map('strtolower', $parameters);
|
||||
|
||||
return [
|
||||
|
Reference in New Issue
Block a user