@@ -2,14 +2,14 @@ |
||
2 | 2 | |
3 | 3 | class CountryCodeException extends \Exception |
4 | 4 | { |
5 | - /** |
|
6 | - * Invalid country code static constructor. |
|
7 | - * |
|
8 | - * @param string $country |
|
9 | - * @return static |
|
10 | - */ |
|
11 | - public static function invalid($country) |
|
12 | - { |
|
13 | - return new static('Invalid country code "' . $country . '".'); |
|
14 | - } |
|
5 | + /** |
|
6 | + * Invalid country code static constructor. |
|
7 | + * |
|
8 | + * @param string $country |
|
9 | + * @return static |
|
10 | + */ |
|
11 | + public static function invalid($country) |
|
12 | + { |
|
13 | + return new static('Invalid country code "' . $country . '".'); |
|
14 | + } |
|
15 | 15 | } |
@@ -2,14 +2,14 @@ |
||
2 | 2 | |
3 | 3 | class NumberFormatException extends \Exception |
4 | 4 | { |
5 | - /** |
|
6 | - * Invalid number format static constructor. |
|
7 | - * |
|
8 | - * @param string $format |
|
9 | - * @return static |
|
10 | - */ |
|
11 | - public static function invalid($format) |
|
12 | - { |
|
13 | - return new static('Invalid number format "' . $format . '".'); |
|
14 | - } |
|
5 | + /** |
|
6 | + * Invalid number format static constructor. |
|
7 | + * |
|
8 | + * @param string $format |
|
9 | + * @return static |
|
10 | + */ |
|
11 | + public static function invalid($format) |
|
12 | + { |
|
13 | + return new static('Invalid number format "' . $format . '".'); |
|
14 | + } |
|
15 | 15 | } |
16 | 16 | \ No newline at end of file |
@@ -10,63 +10,63 @@ |
||
10 | 10 | |
11 | 11 | class PhoneServiceProvider extends ServiceProvider |
12 | 12 | { |
13 | - /** |
|
14 | - * Bootstrap the application events. |
|
15 | - * |
|
16 | - * @return void |
|
17 | - */ |
|
18 | - public function boot() |
|
19 | - { |
|
20 | - $this->registerValidator(); |
|
13 | + /** |
|
14 | + * Bootstrap the application events. |
|
15 | + * |
|
16 | + * @return void |
|
17 | + */ |
|
18 | + public function boot() |
|
19 | + { |
|
20 | + $this->registerValidator(); |
|
21 | 21 | |
22 | - $this->registerRule(); |
|
23 | - } |
|
22 | + $this->registerRule(); |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * Register the service provider. |
|
27 | - * |
|
28 | - * @return void |
|
29 | - */ |
|
30 | - public function register() |
|
31 | - { |
|
32 | - $this->app->singleton('libphonenumber', function ($app) { |
|
33 | - return PhoneNumberUtil::getInstance(); |
|
34 | - }); |
|
25 | + /** |
|
26 | + * Register the service provider. |
|
27 | + * |
|
28 | + * @return void |
|
29 | + */ |
|
30 | + public function register() |
|
31 | + { |
|
32 | + $this->app->singleton('libphonenumber', function ($app) { |
|
33 | + return PhoneNumberUtil::getInstance(); |
|
34 | + }); |
|
35 | 35 | |
36 | - $this->app->alias('libphonenumber', PhoneNumberUtil::class); |
|
37 | - } |
|
36 | + $this->app->alias('libphonenumber', PhoneNumberUtil::class); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Register the "phone" validator. |
|
41 | - */ |
|
42 | - protected function registerValidator() |
|
43 | - { |
|
44 | - $extend = static::canUseDependentValidation() ? 'extendDependent' : 'extend'; |
|
39 | + /** |
|
40 | + * Register the "phone" validator. |
|
41 | + */ |
|
42 | + protected function registerValidator() |
|
43 | + { |
|
44 | + $extend = static::canUseDependentValidation() ? 'extendDependent' : 'extend'; |
|
45 | 45 | |
46 | - $this->app['validator']->{$extend}('phone', Validation\Phone::class . '@validate'); |
|
47 | - } |
|
46 | + $this->app['validator']->{$extend}('phone', Validation\Phone::class . '@validate'); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Register the "phone" rule macro. |
|
51 | - */ |
|
52 | - protected function registerRule() |
|
53 | - { |
|
54 | - if (class_exists('Illuminate\Validation\Rule') && class_uses(Rule::class, Macroable::class)) { |
|
55 | - Rule::macro('phone', function () { |
|
56 | - return new Rules\Phone; |
|
57 | - }); |
|
58 | - } |
|
59 | - } |
|
49 | + /** |
|
50 | + * Register the "phone" rule macro. |
|
51 | + */ |
|
52 | + protected function registerRule() |
|
53 | + { |
|
54 | + if (class_exists('Illuminate\Validation\Rule') && class_uses(Rule::class, Macroable::class)) { |
|
55 | + Rule::macro('phone', function () { |
|
56 | + return new Rules\Phone; |
|
57 | + }); |
|
58 | + } |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Determine whether we can register a dependent validator. |
|
63 | - * |
|
64 | - * @return bool |
|
65 | - */ |
|
66 | - public static function canUseDependentValidation() |
|
67 | - { |
|
68 | - $validator = new ReflectionClass('\Illuminate\Validation\Factory'); |
|
61 | + /** |
|
62 | + * Determine whether we can register a dependent validator. |
|
63 | + * |
|
64 | + * @return bool |
|
65 | + */ |
|
66 | + public static function canUseDependentValidation() |
|
67 | + { |
|
68 | + $validator = new ReflectionClass('\Illuminate\Validation\Factory'); |
|
69 | 69 | |
70 | - return $validator->hasMethod('extendDependent'); |
|
71 | - } |
|
70 | + return $validator->hasMethod('extendDependent'); |
|
71 | + } |
|
72 | 72 | } |
@@ -6,50 +6,50 @@ |
||
6 | 6 | |
7 | 7 | trait ParsesFormats |
8 | 8 | { |
9 | - /** |
|
10 | - * Array of available phone formats. |
|
11 | - * |
|
12 | - * @var array |
|
13 | - */ |
|
14 | - protected static $formats; |
|
9 | + /** |
|
10 | + * Array of available phone formats. |
|
11 | + * |
|
12 | + * @var array |
|
13 | + */ |
|
14 | + protected static $formats; |
|
15 | 15 | |
16 | - /** |
|
17 | - * Determine whether the given format is valid. |
|
18 | - * |
|
19 | - * @param string $format |
|
20 | - * @return bool |
|
21 | - */ |
|
22 | - public static function isValidFormat($format) |
|
23 | - { |
|
24 | - return ! is_null(static::parseFormat($format)); |
|
25 | - } |
|
16 | + /** |
|
17 | + * Determine whether the given format is valid. |
|
18 | + * |
|
19 | + * @param string $format |
|
20 | + * @return bool |
|
21 | + */ |
|
22 | + public static function isValidFormat($format) |
|
23 | + { |
|
24 | + return ! is_null(static::parseFormat($format)); |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * Parse a phone format. |
|
29 | - * |
|
30 | - * @param string $format |
|
31 | - * @return string |
|
32 | - */ |
|
33 | - protected static function parseFormat($format) |
|
34 | - { |
|
35 | - static::loadFormats(); |
|
27 | + /** |
|
28 | + * Parse a phone format. |
|
29 | + * |
|
30 | + * @param string $format |
|
31 | + * @return string |
|
32 | + */ |
|
33 | + protected static function parseFormat($format) |
|
34 | + { |
|
35 | + static::loadFormats(); |
|
36 | 36 | |
37 | - // If the format equals a constant's value, just return it. |
|
38 | - if (in_array($format, static::$formats, true)) { |
|
39 | - return $format; |
|
40 | - } |
|
37 | + // If the format equals a constant's value, just return it. |
|
38 | + if (in_array($format, static::$formats, true)) { |
|
39 | + return $format; |
|
40 | + } |
|
41 | 41 | |
42 | - // Otherwise we'll assume the format is the constant's name. |
|
43 | - return Arr::get(static::$formats, strtoupper($format)); |
|
44 | - } |
|
42 | + // Otherwise we'll assume the format is the constant's name. |
|
43 | + return Arr::get(static::$formats, strtoupper($format)); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Load all available formats once. |
|
48 | - */ |
|
49 | - private static function loadFormats() |
|
50 | - { |
|
51 | - if (! static::$formats) { |
|
52 | - static::$formats = with(new ReflectionClass(PhoneNumberFormat::class))->getConstants(); |
|
53 | - } |
|
54 | - } |
|
46 | + /** |
|
47 | + * Load all available formats once. |
|
48 | + */ |
|
49 | + private static function loadFormats() |
|
50 | + { |
|
51 | + if (! static::$formats) { |
|
52 | + static::$formats = with(new ReflectionClass(PhoneNumberFormat::class))->getConstants(); |
|
53 | + } |
|
54 | + } |
|
55 | 55 | } |
56 | 56 | \ No newline at end of file |
@@ -3,22 +3,22 @@ |
||
3 | 3 | use Propaganistas\LaravelPhone\PhoneNumber; |
4 | 4 | |
5 | 5 | if (! function_exists('phone')) { |
6 | - /** |
|
7 | - * Get a PhoneNumber instance or a formatted string. |
|
8 | - * |
|
9 | - * @param string $number |
|
10 | - * @param string|array $country |
|
11 | - * @param string $format |
|
12 | - * @return string|Propaganistas\LaravelPhone\PhoneNumber |
|
13 | - */ |
|
14 | - function phone($number, $country = [], $format = null) |
|
15 | - { |
|
16 | - $phone = PhoneNumber::make($number, $country); |
|
6 | + /** |
|
7 | + * Get a PhoneNumber instance or a formatted string. |
|
8 | + * |
|
9 | + * @param string $number |
|
10 | + * @param string|array $country |
|
11 | + * @param string $format |
|
12 | + * @return string|Propaganistas\LaravelPhone\PhoneNumber |
|
13 | + */ |
|
14 | + function phone($number, $country = [], $format = null) |
|
15 | + { |
|
16 | + $phone = PhoneNumber::make($number, $country); |
|
17 | 17 | |
18 | - if (! is_null($format)) { |
|
19 | - return $phone->format($format); |
|
20 | - } |
|
18 | + if (! is_null($format)) { |
|
19 | + return $phone->format($format); |
|
20 | + } |
|
21 | 21 | |
22 | - return $phone; |
|
23 | - } |
|
22 | + return $phone; |
|
23 | + } |
|
24 | 24 | } |
@@ -5,39 +5,39 @@ |
||
5 | 5 | |
6 | 6 | trait ParsesCountries |
7 | 7 | { |
8 | - /** |
|
9 | - * Determine whether the given country code is valid. |
|
10 | - * |
|
11 | - * @param string $country |
|
12 | - * @return bool |
|
13 | - */ |
|
14 | - public static function isValidCountryCode($country) |
|
15 | - { |
|
16 | - $iso3166 = new ISO3166; |
|
8 | + /** |
|
9 | + * Determine whether the given country code is valid. |
|
10 | + * |
|
11 | + * @param string $country |
|
12 | + * @return bool |
|
13 | + */ |
|
14 | + public static function isValidCountryCode($country) |
|
15 | + { |
|
16 | + $iso3166 = new ISO3166; |
|
17 | 17 | |
18 | - try { |
|
19 | - $iso3166->alpha2($country); |
|
18 | + try { |
|
19 | + $iso3166->alpha2($country); |
|
20 | 20 | |
21 | - return true; |
|
22 | - } catch (\Exception $e) { |
|
23 | - return false; |
|
24 | - } |
|
25 | - } |
|
21 | + return true; |
|
22 | + } catch (\Exception $e) { |
|
23 | + return false; |
|
24 | + } |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * Parse the provided phone countries to a valid array. |
|
29 | - * |
|
30 | - * @param string|array $countries |
|
31 | - * @return array |
|
32 | - */ |
|
33 | - protected function parseCountries($countries) |
|
34 | - { |
|
35 | - return Collection::make(is_array($countries) ? $countries : func_get_args()) |
|
36 | - ->map(function ($country) { |
|
37 | - return strtoupper($country); |
|
38 | - }) |
|
39 | - ->filter(function ($value) { |
|
40 | - return static::isValidCountryCode($value); |
|
41 | - })->toArray(); |
|
42 | - } |
|
27 | + /** |
|
28 | + * Parse the provided phone countries to a valid array. |
|
29 | + * |
|
30 | + * @param string|array $countries |
|
31 | + * @return array |
|
32 | + */ |
|
33 | + protected function parseCountries($countries) |
|
34 | + { |
|
35 | + return Collection::make(is_array($countries) ? $countries : func_get_args()) |
|
36 | + ->map(function ($country) { |
|
37 | + return strtoupper($country); |
|
38 | + }) |
|
39 | + ->filter(function ($value) { |
|
40 | + return static::isValidCountryCode($value); |
|
41 | + })->toArray(); |
|
42 | + } |
|
43 | 43 | } |
44 | 44 | \ No newline at end of file |
@@ -4,14 +4,14 @@ |
||
4 | 4 | |
5 | 5 | class InvalidParameterException extends \Exception |
6 | 6 | { |
7 | - /** |
|
8 | - * Ambiguous parameter static constructor. |
|
9 | - * |
|
10 | - * @param string $parameter |
|
11 | - * @return static |
|
12 | - */ |
|
13 | - public static function ambiguous($parameter) |
|
14 | - { |
|
15 | - return new static('Ambiguous phone validation parameter: "' . $parameter . '". This parameter is recognized as an input field and as a phone type. Please rename the input field.'); |
|
16 | - } |
|
7 | + /** |
|
8 | + * Ambiguous parameter static constructor. |
|
9 | + * |
|
10 | + * @param string $parameter |
|
11 | + * @return static |
|
12 | + */ |
|
13 | + public static function ambiguous($parameter) |
|
14 | + { |
|
15 | + return new static('Ambiguous phone validation parameter: "' . $parameter . '". This parameter is recognized as an input field and as a phone type. Please rename the input field.'); |
|
16 | + } |
|
17 | 17 | } |
@@ -5,69 +5,69 @@ |
||
5 | 5 | |
6 | 6 | class NumberParseException extends libNumberParseException |
7 | 7 | { |
8 | - /** |
|
9 | - * @var string |
|
10 | - */ |
|
11 | - protected $number; |
|
8 | + /** |
|
9 | + * @var string |
|
10 | + */ |
|
11 | + protected $number; |
|
12 | 12 | |
13 | - /** |
|
14 | - * @var array |
|
15 | - */ |
|
16 | - protected $countries = []; |
|
13 | + /** |
|
14 | + * @var array |
|
15 | + */ |
|
16 | + protected $countries = []; |
|
17 | 17 | |
18 | - /** |
|
19 | - * Country specification required static constructor. |
|
20 | - * |
|
21 | - * @param string $number |
|
22 | - * @return static |
|
23 | - */ |
|
24 | - public static function countryRequired($number) |
|
25 | - { |
|
26 | - $exception = new static( |
|
27 | - libNumberParseException::INVALID_COUNTRY_CODE, |
|
28 | - 'Number requires a country to be specified.' |
|
29 | - ); |
|
18 | + /** |
|
19 | + * Country specification required static constructor. |
|
20 | + * |
|
21 | + * @param string $number |
|
22 | + * @return static |
|
23 | + */ |
|
24 | + public static function countryRequired($number) |
|
25 | + { |
|
26 | + $exception = new static( |
|
27 | + libNumberParseException::INVALID_COUNTRY_CODE, |
|
28 | + 'Number requires a country to be specified.' |
|
29 | + ); |
|
30 | 30 | |
31 | - $exception->number = $number; |
|
31 | + $exception->number = $number; |
|
32 | 32 | |
33 | - return $exception; |
|
34 | - } |
|
33 | + return $exception; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Country mismatch static constructor. |
|
38 | - * |
|
39 | - * @param string $number |
|
40 | - * @param string|array $country |
|
41 | - * @return static |
|
42 | - */ |
|
43 | - public static function countryMismatch($number, $countries) |
|
44 | - { |
|
45 | - $countries = array_filter(is_array($countries) ? $countries : [$countries]); |
|
36 | + /** |
|
37 | + * Country mismatch static constructor. |
|
38 | + * |
|
39 | + * @param string $number |
|
40 | + * @param string|array $country |
|
41 | + * @return static |
|
42 | + */ |
|
43 | + public static function countryMismatch($number, $countries) |
|
44 | + { |
|
45 | + $countries = array_filter(is_array($countries) ? $countries : [$countries]); |
|
46 | 46 | |
47 | - $exception = new static( |
|
48 | - libNumberParseException::INVALID_COUNTRY_CODE, |
|
49 | - 'Number does not match the provided '. Str::plural('country', count($countries)).'.' |
|
50 | - ); |
|
47 | + $exception = new static( |
|
48 | + libNumberParseException::INVALID_COUNTRY_CODE, |
|
49 | + 'Number does not match the provided '. Str::plural('country', count($countries)).'.' |
|
50 | + ); |
|
51 | 51 | |
52 | - $exception->number = $number; |
|
53 | - $exception->countries = $countries; |
|
52 | + $exception->number = $number; |
|
53 | + $exception->countries = $countries; |
|
54 | 54 | |
55 | - return $exception; |
|
56 | - } |
|
55 | + return $exception; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @return string |
|
60 | - */ |
|
61 | - public function getNumber() |
|
62 | - { |
|
63 | - return $this->number; |
|
64 | - } |
|
58 | + /** |
|
59 | + * @return string |
|
60 | + */ |
|
61 | + public function getNumber() |
|
62 | + { |
|
63 | + return $this->number; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @return array |
|
68 | - */ |
|
69 | - public function getCountries() |
|
70 | - { |
|
71 | - return $this->countries; |
|
72 | - } |
|
66 | + /** |
|
67 | + * @return array |
|
68 | + */ |
|
69 | + public function getCountries() |
|
70 | + { |
|
71 | + return $this->countries; |
|
72 | + } |
|
73 | 73 | } |
74 | 74 | \ No newline at end of file |
@@ -6,149 +6,149 @@ |
||
6 | 6 | |
7 | 7 | class Phone |
8 | 8 | { |
9 | - use ParsesTypes; |
|
9 | + use ParsesTypes; |
|
10 | 10 | |
11 | - /** |
|
12 | - * The provided phone countries. |
|
13 | - * |
|
14 | - * @var array |
|
15 | - */ |
|
16 | - protected $countries = []; |
|
17 | - |
|
18 | - /** |
|
19 | - * The input field name to check for a country value. |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $countryField; |
|
24 | - |
|
25 | - /** |
|
26 | - * The provided phone types. |
|
27 | - * |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - protected $types = []; |
|
31 | - |
|
32 | - /** |
|
33 | - * Whether the number's country should be auto-detected. |
|
34 | - * |
|
35 | - * @var bool |
|
36 | - */ |
|
37 | - protected $detect = false; |
|
38 | - |
|
39 | - /** |
|
40 | - * Whether to allow lenient checks (i.e. landline numbers without area codes). |
|
41 | - * |
|
42 | - * @var bool |
|
43 | - */ |
|
44 | - protected $lenient = false; |
|
45 | - |
|
46 | - /** |
|
47 | - * Set the phone countries. |
|
48 | - * |
|
49 | - * @param string|array $country |
|
50 | - * @return $this |
|
51 | - */ |
|
52 | - public function country($country) |
|
53 | - { |
|
54 | - $countries = is_array($country) ? $country : func_get_args(); |
|
55 | - |
|
56 | - $this->countries = array_merge($this->countries, $countries); |
|
57 | - |
|
58 | - return $this; |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Set the country input field. |
|
63 | - * |
|
64 | - * @param string $name |
|
65 | - * @return $this |
|
66 | - */ |
|
67 | - public function countryField($name) |
|
68 | - { |
|
69 | - $this->countryField = $name; |
|
70 | - |
|
71 | - return $this; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Set the phone types. |
|
76 | - * |
|
77 | - * @param string|array $type |
|
78 | - * @return $this |
|
79 | - */ |
|
80 | - public function type($type) |
|
81 | - { |
|
82 | - $types = is_array($type) ? $type : func_get_args(); |
|
83 | - |
|
84 | - $this->types = array_merge($this->types, $types); |
|
85 | - |
|
86 | - return $this; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Shortcut method for mobile type restriction. |
|
91 | - * |
|
92 | - * @return $this |
|
93 | - */ |
|
94 | - public function mobile() |
|
95 | - { |
|
96 | - $this->type(PhoneNumberType::MOBILE); |
|
97 | - |
|
98 | - return $this; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Shortcut method for fixed line type restriction. |
|
103 | - * |
|
104 | - * @return $this |
|
105 | - */ |
|
106 | - public function fixedLine() |
|
107 | - { |
|
108 | - $this->type(PhoneNumberType::FIXED_LINE); |
|
109 | - |
|
110 | - return $this; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Enable automatic country detection. |
|
115 | - * |
|
116 | - * @return $this |
|
117 | - */ |
|
118 | - public function detect() |
|
119 | - { |
|
120 | - $this->detect = true; |
|
121 | - |
|
122 | - return $this; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Enable lenient number checking. |
|
127 | - * |
|
128 | - * @return $this |
|
129 | - */ |
|
130 | - public function lenient() |
|
131 | - { |
|
132 | - $this->lenient = true; |
|
133 | - |
|
134 | - return $this; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Convert the rule to a validation string. |
|
139 | - * |
|
140 | - * @return string |
|
141 | - */ |
|
142 | - public function __toString() |
|
143 | - { |
|
144 | - $parameters = implode(',', array_merge( |
|
145 | - $this->countries, |
|
146 | - static::parseTypes($this->types), |
|
147 | - ($this->countryField ? [$this->countryField]: []), |
|
148 | - ($this->detect ? ['AUTO'] : []), |
|
149 | - ($this->lenient ? ['LENIENT'] : []) |
|
150 | - )); |
|
151 | - |
|
152 | - return 'phone' . (! empty($parameters) ? ":$parameters" : ''); |
|
153 | - } |
|
11 | + /** |
|
12 | + * The provided phone countries. |
|
13 | + * |
|
14 | + * @var array |
|
15 | + */ |
|
16 | + protected $countries = []; |
|
17 | + |
|
18 | + /** |
|
19 | + * The input field name to check for a country value. |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $countryField; |
|
24 | + |
|
25 | + /** |
|
26 | + * The provided phone types. |
|
27 | + * |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + protected $types = []; |
|
31 | + |
|
32 | + /** |
|
33 | + * Whether the number's country should be auto-detected. |
|
34 | + * |
|
35 | + * @var bool |
|
36 | + */ |
|
37 | + protected $detect = false; |
|
38 | + |
|
39 | + /** |
|
40 | + * Whether to allow lenient checks (i.e. landline numbers without area codes). |
|
41 | + * |
|
42 | + * @var bool |
|
43 | + */ |
|
44 | + protected $lenient = false; |
|
45 | + |
|
46 | + /** |
|
47 | + * Set the phone countries. |
|
48 | + * |
|
49 | + * @param string|array $country |
|
50 | + * @return $this |
|
51 | + */ |
|
52 | + public function country($country) |
|
53 | + { |
|
54 | + $countries = is_array($country) ? $country : func_get_args(); |
|
55 | + |
|
56 | + $this->countries = array_merge($this->countries, $countries); |
|
57 | + |
|
58 | + return $this; |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Set the country input field. |
|
63 | + * |
|
64 | + * @param string $name |
|
65 | + * @return $this |
|
66 | + */ |
|
67 | + public function countryField($name) |
|
68 | + { |
|
69 | + $this->countryField = $name; |
|
70 | + |
|
71 | + return $this; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Set the phone types. |
|
76 | + * |
|
77 | + * @param string|array $type |
|
78 | + * @return $this |
|
79 | + */ |
|
80 | + public function type($type) |
|
81 | + { |
|
82 | + $types = is_array($type) ? $type : func_get_args(); |
|
83 | + |
|
84 | + $this->types = array_merge($this->types, $types); |
|
85 | + |
|
86 | + return $this; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Shortcut method for mobile type restriction. |
|
91 | + * |
|
92 | + * @return $this |
|
93 | + */ |
|
94 | + public function mobile() |
|
95 | + { |
|
96 | + $this->type(PhoneNumberType::MOBILE); |
|
97 | + |
|
98 | + return $this; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Shortcut method for fixed line type restriction. |
|
103 | + * |
|
104 | + * @return $this |
|
105 | + */ |
|
106 | + public function fixedLine() |
|
107 | + { |
|
108 | + $this->type(PhoneNumberType::FIXED_LINE); |
|
109 | + |
|
110 | + return $this; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Enable automatic country detection. |
|
115 | + * |
|
116 | + * @return $this |
|
117 | + */ |
|
118 | + public function detect() |
|
119 | + { |
|
120 | + $this->detect = true; |
|
121 | + |
|
122 | + return $this; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Enable lenient number checking. |
|
127 | + * |
|
128 | + * @return $this |
|
129 | + */ |
|
130 | + public function lenient() |
|
131 | + { |
|
132 | + $this->lenient = true; |
|
133 | + |
|
134 | + return $this; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Convert the rule to a validation string. |
|
139 | + * |
|
140 | + * @return string |
|
141 | + */ |
|
142 | + public function __toString() |
|
143 | + { |
|
144 | + $parameters = implode(',', array_merge( |
|
145 | + $this->countries, |
|
146 | + static::parseTypes($this->types), |
|
147 | + ($this->countryField ? [$this->countryField]: []), |
|
148 | + ($this->detect ? ['AUTO'] : []), |
|
149 | + ($this->lenient ? ['LENIENT'] : []) |
|
150 | + )); |
|
151 | + |
|
152 | + return 'phone' . (! empty($parameters) ? ":$parameters" : ''); |
|
153 | + } |
|
154 | 154 | } |