PHP Class Propaganistas\LaravelPhone\PhoneValidator

Show file Open project: propaganistas/laravel-phone

Protected Properties

Property Type Description
$autodetect boolean Whether the country should be auto-detected.
$countries array Countries to validate against.
$countryField string | null The field to use for country if not passed as a parameter.
$data array Dotted validator data.
$lenient boolean Whether to allow lenient checking of numbers (i.e. landline without area codes).
$lib libphonenumber\PhoneNumberUtil
$types array Transformed phone number types to validate against.

Public Methods

Method Description
__construct ( PhoneNumberUtil $lib ) PhoneValidator constructor.
isInputField ( string $field ) : boolean Checks if the given field is an actual input field.
isPhoneCountry ( string $country ) : boolean Checks if the supplied string is a valid country code.
isPhoneType ( string $type ) : boolean Checks if the supplied string is a valid phone number type.
validatePhone ( string $attribute, mixed $value, array $parameters, object $validator ) : boolean Validates a phone number.

Protected Methods

Method Description
assignParameters ( array $parameters ) Parses the supplied validator parameters.
checkCountries ( string $attribute ) Checks the detected countries. Overrides countries if a country field is present.
isValidNumber ( mixed $number, null $country = null ) : boolean Performs the actual validation of the phone number.
parseTypes ( array $types ) : array Parses the supplied phone number types.

Method Details

__construct() public method

PhoneValidator constructor.
public __construct ( PhoneNumberUtil $lib )
$lib libphonenumber\PhoneNumberUtil

assignParameters() protected method

Parses the supplied validator parameters.
protected assignParameters ( array $parameters )
$parameters array

checkCountries() protected method

When using a country field, we should validate to false if country is empty so no exception will be thrown.
protected checkCountries ( string $attribute )
$attribute string

isInputField() public method

Checks if the given field is an actual input field.
public isInputField ( string $field ) : boolean
$field string
return boolean

isPhoneCountry() public method

Checks if the supplied string is a valid country code.
public isPhoneCountry ( string $country ) : boolean
$country string
return boolean

isPhoneType() public method

Checks if the supplied string is a valid phone number type.
public isPhoneType ( string $type ) : boolean
$type string
return boolean

isValidNumber() protected method

Performs the actual validation of the phone number.
protected isValidNumber ( mixed $number, null $country = null ) : boolean
$number mixed
$country null
return boolean

parseTypes() protected method

Parses the supplied phone number types.
protected parseTypes ( array $types ) : array
$types array
return array

validatePhone() public method

Validates a phone number.
public validatePhone ( string $attribute, mixed $value, array $parameters, object $validator ) : boolean
$attribute string
$value mixed
$parameters array
$validator object
return boolean

Property Details

$autodetect protected property

Whether the country should be auto-detected.
protected bool $autodetect
return boolean

$countries protected property

Countries to validate against.
protected array $countries
return array

$countryField protected property

The field to use for country if not passed as a parameter.
protected string|null $countryField
return string | null

$data protected property

Dotted validator data.
protected array $data
return array

$lenient protected property

Whether to allow lenient checking of numbers (i.e. landline without area codes).
protected bool $lenient
return boolean

$lib protected property

protected PhoneNumberUtil,libphonenumber $lib
return libphonenumber\PhoneNumberUtil

$types protected property

Transformed phone number types to validate against.
protected array $types
return array