My first commit of codes
This commit is contained in:
4
vendor/propaganistas/laravel-phone/.gitignore
vendored
Normal file
4
vendor/propaganistas/laravel-phone/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
/vendor
|
||||
composer.phar
|
||||
composer.lock
|
||||
.DS_Store
|
||||
13
vendor/propaganistas/laravel-phone/.travis.yml
vendored
Normal file
13
vendor/propaganistas/laravel-phone/.travis.yml
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.4
|
||||
- 5.5
|
||||
- 5.6
|
||||
- hhvm
|
||||
|
||||
before_script:
|
||||
- composer self-update
|
||||
- composer install --prefer-source --no-interaction --dev
|
||||
|
||||
script: phpunit
|
||||
20
vendor/propaganistas/laravel-phone/LICENSE
vendored
Normal file
20
vendor/propaganistas/laravel-phone/LICENSE
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Propaganistas
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
75
vendor/propaganistas/laravel-phone/README.md
vendored
Normal file
75
vendor/propaganistas/laravel-phone/README.md
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
# Laravel Phone Validator
|
||||
|
||||
Adds a phone validator to Laravel 5 based on the [PHP port](https://github.com/giggsey/libphonenumber-for-php) of [Google's libphonenumber API](https://code.google.com/p/libphonenumber/) by [giggsey](https://github.com/giggsey).
|
||||
|
||||
### Installation
|
||||
|
||||
1. In the `require` key of `composer.json` file add the following
|
||||
|
||||
```json
|
||||
"propaganistas/laravel-phone": "~2.0"
|
||||
```
|
||||
|
||||
If you need the Laravel 4 version, you can point at version `~1.2` or head over to the `Laravel4` branch.
|
||||
|
||||
2. Run the Composer update comand
|
||||
|
||||
```bash
|
||||
$ composer update
|
||||
```
|
||||
|
||||
3. In your `app/config/app.php` add `'Propaganistas\LaravelPhone\LaravelPhoneServiceProvider',` to the end of the `$providers` array
|
||||
|
||||
```php
|
||||
'providers' => [
|
||||
'Illuminate\Foundation\Providers\ArtisanServiceProvider',
|
||||
'Illuminate\Auth\AuthServiceProvider',
|
||||
...
|
||||
'Propaganistas\LaravelPhone\LaravelPhoneServiceProvider',
|
||||
],
|
||||
```
|
||||
|
||||
4. In your languages directory, add for each language an extra language line for the validator:
|
||||
|
||||
```php
|
||||
"phone" => "The :attribute field contains an invalid number.",
|
||||
```
|
||||
|
||||
### Usage
|
||||
|
||||
To validate a field using the phone validator, use the `phone` keyword in your validation rules array. The phone validator is able to operate in two ways.
|
||||
|
||||
- You either specify *ISO 3166-1 compliant* country codes yourself as parameters for the validator, e.g.:
|
||||
|
||||
```php
|
||||
public static $rules = [
|
||||
'phonefield' => 'phone:US,BE',
|
||||
];
|
||||
```
|
||||
|
||||
The validator will check if the number is valid in at least one of provided countries, so feel free to add as many country codes as you like.
|
||||
|
||||
- Or you don't specify any parameters but you plug in a dedicated country input field (keyed by *ISO 3166-1 compliant* country codes) to allow end users to supply a country on their own. The easiest method by far is to install the [CountryList package by monarobase](https://github.com/Monarobase/country-list). The country field has to be named similar to the phone field but with `_country` appended:
|
||||
|
||||
```php
|
||||
public static $rules = [
|
||||
'phonefield' => 'phone',
|
||||
'phonefield_country' => 'required_with:phonefield',
|
||||
];
|
||||
```
|
||||
|
||||
If using the CountryList package, you could then use the following in the form view:
|
||||
|
||||
```php
|
||||
{{ Form::text('phonefield') }}
|
||||
{{ Form::select('phonefield_country', Countries::getList(App::getLocale(), 'php', 'cldr')) }}
|
||||
```
|
||||
|
||||
### Display
|
||||
Format a fetched phone value using the helper function:
|
||||
|
||||
```php
|
||||
phone_format($phone_number, $country_code, $format = null)
|
||||
```
|
||||
|
||||
The `$format` parameter is optional and should be a constant of `\libphonenumber\PhoneNumberFormat` (defaults to `\libphonenumber\PhoneNumberFormat::INTERNATIONAL`)
|
||||
30
vendor/propaganistas/laravel-phone/composer.json
vendored
Normal file
30
vendor/propaganistas/laravel-phone/composer.json
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "propaganistas/laravel-phone",
|
||||
"description": "Adds a phone validator to Laravel based on Google's libphonenumber API.",
|
||||
"keywords": ["laravel", "libphonenumber", "validation", "phone"],
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Propaganistas",
|
||||
"email": "Propaganistas@users.noreply.github.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.4.0",
|
||||
"illuminate/support": "~5.0",
|
||||
"illuminate/validation": "~5.0",
|
||||
"giggsey/libphonenumber-for-php": "~7.0"
|
||||
},
|
||||
"suggest": {
|
||||
"monarobase/country-list": "Adds a compatible (and fully translated) country list API."
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Propaganistas\\LaravelPhone": "src/"
|
||||
},
|
||||
"files": [
|
||||
"helpers.php"
|
||||
]
|
||||
},
|
||||
"prefer-stable": true
|
||||
}
|
||||
8
vendor/propaganistas/laravel-phone/helpers.php
vendored
Normal file
8
vendor/propaganistas/laravel-phone/helpers.php
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
function phone_format($phone, $country, $format = null) {
|
||||
$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
|
||||
$phoneProto = $phoneUtil->parse($phone, $country);
|
||||
$format = is_null($format) ? \libphonenumber\PhoneNumberFormat::INTERNATIONAL : $format;
|
||||
return $phoneUtil->format($phoneProto, $format);
|
||||
}
|
||||
18
vendor/propaganistas/laravel-phone/phpunit.xml
vendored
Normal file
18
vendor/propaganistas/laravel-phone/phpunit.xml
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
bootstrap="vendor/autoload.php"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="Package Test Suite">
|
||||
<directory suffix=".php">./tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
||||
5
vendor/propaganistas/laravel-phone/provides.json
vendored
Normal file
5
vendor/propaganistas/laravel-phone/provides.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"providers": [
|
||||
"Propaganistas\\LaravelPhone\\LaravelPhoneServiceProvider"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php namespace Propaganistas\LaravelPhone;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class LaravelPhoneServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = false;
|
||||
|
||||
/**
|
||||
* Bootstrap the application events.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->app['validator']->extend('phone', 'Propaganistas\LaravelPhone\Validator@phone');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register() {}
|
||||
}
|
||||
54
vendor/propaganistas/laravel-phone/src/Propaganistas/LaravelPhone/Validator.php
vendored
Normal file
54
vendor/propaganistas/laravel-phone/src/Propaganistas/LaravelPhone/Validator.php
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php namespace Propaganistas\LaravelPhone;
|
||||
|
||||
class Validator
|
||||
{
|
||||
/**
|
||||
* Validates a phone number field using libphonenumber.
|
||||
*/
|
||||
public function phone($attribute, $value, $parameters, $validator)
|
||||
{
|
||||
$data = $validator->getData();
|
||||
// Check if we should validate using a default country or a *_country field.
|
||||
if (!empty($parameters)) {
|
||||
$countries = $parameters;
|
||||
}
|
||||
elseif (isset($data[$attribute.'_country'])) {
|
||||
$countries = array($data[$attribute.'_country']);
|
||||
}
|
||||
else {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Filter out invalid countries.
|
||||
foreach ($countries as $key => $country) {
|
||||
if (!$this->phone_country($country)) {
|
||||
unset($countries[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
// Now try each country during validation.
|
||||
foreach ($countries as $country) {
|
||||
$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
|
||||
try {
|
||||
$phoneProto = $phoneUtil->parse($value, $country);
|
||||
if ($phoneUtil->isValidNumber($phoneProto)) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
catch (\libphonenumber\NumberParseException $e) {}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides some arbitrary validation regarding the _country field to only allow
|
||||
* country codes libphonenumber can handle.
|
||||
* If using a package based on umpirsky/country-list, invalidate the option 'ZZ => Unknown or invalid region'.
|
||||
*/
|
||||
public function phone_country($country)
|
||||
{
|
||||
return (strlen($country) === 2 && ctype_alpha($country) && ctype_upper($country) && $country != 'ZZ');
|
||||
}
|
||||
|
||||
}
|
||||
0
vendor/propaganistas/laravel-phone/tests/.gitkeep
vendored
Normal file
0
vendor/propaganistas/laravel-phone/tests/.gitkeep
vendored
Normal file
Reference in New Issue
Block a user