mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-31 07:01:54 +00:00
Compare commits
No commits in common. "master" and "v1.4.3" have entirely different histories.
1
.github/FUNDING.yml
vendored
1
.github/FUNDING.yml
vendored
@ -1 +0,0 @@
|
|||||||
tidelift: "packagist/vlucas/valitron"
|
|
||||||
73
.github/workflows/test.yml
vendored
73
.github/workflows/test.yml
vendored
@ -1,73 +0,0 @@
|
|||||||
name: Run Tests
|
|
||||||
|
|
||||||
on: [push, pull_request]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
runs-on: ${{ matrix.operating-system }}
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
operating-system: ['ubuntu-latest']
|
|
||||||
php-versions:
|
|
||||||
- '5.4'
|
|
||||||
- '5.5'
|
|
||||||
- '5.6'
|
|
||||||
- '7.0'
|
|
||||||
- '7.1'
|
|
||||||
- '7.2'
|
|
||||||
- '7.3'
|
|
||||||
- '7.4'
|
|
||||||
- '8.0'
|
|
||||||
# - '8.1'
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
- name: Setup PHP
|
|
||||||
uses: shivammathur/setup-php@v2
|
|
||||||
with:
|
|
||||||
php-version: ${{ matrix.php-versions }}
|
|
||||||
- name: Cache composer packages
|
|
||||||
id: composer-cache
|
|
||||||
uses: actions/cache@v2
|
|
||||||
with:
|
|
||||||
path: vendor
|
|
||||||
key: ${{ runner.os }}-php-${{ matrix.php-versions }}-${{ hashFiles('**/composer.lock') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-php-${{ matrix.php-versions }}-
|
|
||||||
- name: Validate composer configuration
|
|
||||||
run: |
|
|
||||||
composer validate
|
|
||||||
- name: Install dependencies
|
|
||||||
run: |
|
|
||||||
composer install --no-progress
|
|
||||||
- name: Run tests
|
|
||||||
run: |
|
|
||||||
composer run-script test
|
|
||||||
|
|
||||||
# test-hhvm:
|
|
||||||
# runs-on: ubuntu-latest
|
|
||||||
# steps:
|
|
||||||
# - name: Checkout
|
|
||||||
# uses: actions/checkout@v2
|
|
||||||
# - name: Setup HHVM
|
|
||||||
# uses: azjezz/setup-hhvm@v1
|
|
||||||
# with:
|
|
||||||
# version: latest
|
|
||||||
# debug: false
|
|
||||||
# - name: Cache composer packages
|
|
||||||
# id: composer-cache
|
|
||||||
# uses: actions/cache@v2
|
|
||||||
# with:
|
|
||||||
# path: vendor
|
|
||||||
# key: ${{ runner.os }}-hhvm-${{ hashFiles('**/composer.lock') }}
|
|
||||||
# restore-keys: |
|
|
||||||
# ${{ runner.os }}-hhvm-
|
|
||||||
# - name: Validate composer configuration
|
|
||||||
# run: |
|
|
||||||
# composer validate
|
|
||||||
# - name: Install dependencies
|
|
||||||
# run: |
|
|
||||||
# composer install --no-progress
|
|
||||||
# - name: Run tests
|
|
||||||
# run: |
|
|
||||||
# composer run-script test
|
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,5 +2,3 @@
|
|||||||
composer.phar
|
composer.phar
|
||||||
composer.lock
|
composer.lock
|
||||||
vendor
|
vendor
|
||||||
.idea/
|
|
||||||
.phpunit.result.cache
|
|
||||||
27
.travis.yml
Normal file
27
.travis.yml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# see http://about.travis-ci.org/docs/user/languages/php/ for more hints
|
||||||
|
language: php
|
||||||
|
|
||||||
|
# list any PHP version you want to test against
|
||||||
|
php:
|
||||||
|
- 5.4
|
||||||
|
- 5.5
|
||||||
|
- 5.6
|
||||||
|
- 7.0
|
||||||
|
- 7.1
|
||||||
|
- 7.2
|
||||||
|
- nightly
|
||||||
|
- hhvm
|
||||||
|
|
||||||
|
matrix:
|
||||||
|
allow_failures:
|
||||||
|
- php: hhvm
|
||||||
|
- php: nightly
|
||||||
|
include:
|
||||||
|
- php: 5.3
|
||||||
|
dist: precise
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- composer install
|
||||||
|
|
||||||
|
# Script to run tests
|
||||||
|
script: composer test
|
||||||
@ -3,20 +3,20 @@
|
|||||||
"type": "library",
|
"type": "library",
|
||||||
"description": "Simple, elegant, stand-alone validation library with NO dependencies",
|
"description": "Simple, elegant, stand-alone validation library with NO dependencies",
|
||||||
"keywords": ["validation", "validator", "valid"],
|
"keywords": ["validation", "validator", "valid"],
|
||||||
"homepage": "https://github.com/vlucas/valitron",
|
"homepage": "http://github.com/vlucas/valitron",
|
||||||
"license": "BSD-3-Clause",
|
"license" : "BSD-3-Clause",
|
||||||
"authors": [
|
"authors" : [
|
||||||
{
|
{
|
||||||
"name": "Vance Lucas",
|
"name": "Vance Lucas",
|
||||||
"email": "vance@vancelucas.com",
|
"email": "vance@vancelucas.com",
|
||||||
"homepage": "https://www.vancelucas.com"
|
"homepage": "http://www.vancelucas.com"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.3.2"
|
"php": ">=5.3.2"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": ">=4.8.35"
|
"phpunit/phpunit": "^4.8.35 || ^5.5 || ^6.5"
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
"ext-mbstring": "It can support the multiple bytes string length."
|
"ext-mbstring": "It can support the multiple bytes string length."
|
||||||
|
|||||||
@ -11,7 +11,6 @@ return array(
|
|||||||
'min' => "يجب ان يكون اعلي من %s",
|
'min' => "يجب ان يكون اعلي من %s",
|
||||||
'max' => "يجب ان يكون اقل من %s",
|
'max' => "يجب ان يكون اقل من %s",
|
||||||
'in' => "الُمدخل يغير صحيح",
|
'in' => "الُمدخل يغير صحيح",
|
||||||
'listContains' => "الُمدخل يغير صحيح",
|
|
||||||
'notIn' => "الُمدخل يغير صحيح",
|
'notIn' => "الُمدخل يغير صحيح",
|
||||||
'ip' => "رقم الإتصال غير صحيح",
|
'ip' => "رقم الإتصال غير صحيح",
|
||||||
'email' => "البريد الألكتروني غير صحيح",
|
'email' => "البريد الألكتروني غير صحيح",
|
||||||
|
|||||||
@ -10,7 +10,6 @@ return array(
|
|||||||
'length' => "%d qədər uzunluğu olmalıdır",
|
'length' => "%d qədər uzunluğu olmalıdır",
|
||||||
'min' => "minimum %s qədər olmalıdır",
|
'min' => "minimum %s qədər olmalıdır",
|
||||||
'max' => "maksimum %s qədər olmalıdır",
|
'max' => "maksimum %s qədər olmalıdır",
|
||||||
'listContains' => "yalnış dəyər ehtiva edir",
|
|
||||||
'in' => "yalnış dəyər ehtiva edir",
|
'in' => "yalnış dəyər ehtiva edir",
|
||||||
'notIn' => "yalnış dəyər ehtiva edir",
|
'notIn' => "yalnış dəyər ehtiva edir",
|
||||||
'ip' => "düzgün IP ünvanı deyil",
|
'ip' => "düzgün IP ünvanı deyil",
|
||||||
|
|||||||
@ -10,7 +10,6 @@ return array(
|
|||||||
'length' => "трябва да бъде %d символа дълго",
|
'length' => "трябва да бъде %d символа дълго",
|
||||||
'min' => "трябвя да бъде поне %s",
|
'min' => "трябвя да бъде поне %s",
|
||||||
'max' => "трябва да бъде не повече от %s",
|
'max' => "трябва да бъде не повече от %s",
|
||||||
'listContains' => "съдържа невалидна стойност",
|
|
||||||
'in' => "съдържа невалидна стойност",
|
'in' => "съдържа невалидна стойност",
|
||||||
'notIn' => "съдържа невалидна стойност",
|
'notIn' => "съдържа невалидна стойност",
|
||||||
'ip' => "е невалиден IP адрес",
|
'ip' => "е невалиден IP адрес",
|
||||||
|
|||||||
@ -10,7 +10,6 @@ return array(
|
|||||||
'length' => "kann nicht länger als %d sein",
|
'length' => "kann nicht länger als %d sein",
|
||||||
'min' => "muss größer als %s sein",
|
'min' => "muss größer als %s sein",
|
||||||
'max' => "muss kleiner als %s sein",
|
'max' => "muss kleiner als %s sein",
|
||||||
'listContains' => "enthält einen ungültigen Wert",
|
|
||||||
'in' => "enthält einen ungültigen Wert",
|
'in' => "enthält einen ungültigen Wert",
|
||||||
'notIn' => "enthält einen ungültigen Wert",
|
'notIn' => "enthält einen ungültigen Wert",
|
||||||
'ip' => "enthält keine gültige IP-Addresse",
|
'ip' => "enthält keine gültige IP-Addresse",
|
||||||
|
|||||||
@ -10,7 +10,6 @@ return array(
|
|||||||
'length' => "πρέπει να είναι μεγαλύτερο από %d",
|
'length' => "πρέπει να είναι μεγαλύτερο από %d",
|
||||||
'min' => "πρέπει να είναι τουλάχιστον %s",
|
'min' => "πρέπει να είναι τουλάχιστον %s",
|
||||||
'max' => "δεν πρέπει να είναι περισσότερο από %s",
|
'max' => "δεν πρέπει να είναι περισσότερο από %s",
|
||||||
'listContains' => "περιέχει μη έγκυρη τιμή",
|
|
||||||
'in' => "περιέχει μη έγκυρη τιμή",
|
'in' => "περιέχει μη έγκυρη τιμή",
|
||||||
'notIn' => "περιέχει μη έγκυρη τιμή",
|
'notIn' => "περιέχει μη έγκυρη τιμή",
|
||||||
'ip' => "δεν είναι έγκυρη διεύθυνση IP",
|
'ip' => "δεν είναι έγκυρη διεύθυνση IP",
|
||||||
|
|||||||
10
lang/en.php
10
lang/en.php
@ -10,12 +10,9 @@ return array(
|
|||||||
'length' => "must be %d characters long",
|
'length' => "must be %d characters long",
|
||||||
'min' => "must be at least %s",
|
'min' => "must be at least %s",
|
||||||
'max' => "must be no more than %s",
|
'max' => "must be no more than %s",
|
||||||
'listContains' => "contains invalid value",
|
|
||||||
'in' => "contains invalid value",
|
'in' => "contains invalid value",
|
||||||
'notIn' => "contains invalid value",
|
'notIn' => "contains invalid value",
|
||||||
'ip' => "is not a valid IP address",
|
'ip' => "is not a valid IP address",
|
||||||
'ipv4' => "is not a valid IPv4 address",
|
|
||||||
'ipv6' => "is not a valid IPv6 address",
|
|
||||||
'email' => "is not a valid email address",
|
'email' => "is not a valid email address",
|
||||||
'url' => "is not a valid URL",
|
'url' => "is not a valid URL",
|
||||||
'urlActive' => "must be an active domain",
|
'urlActive' => "must be an active domain",
|
||||||
@ -33,10 +30,5 @@ return array(
|
|||||||
'creditCard' => "must be a valid credit card number",
|
'creditCard' => "must be a valid credit card number",
|
||||||
'lengthMin' => "must be at least %d characters long",
|
'lengthMin' => "must be at least %d characters long",
|
||||||
'lengthMax' => "must not exceed %d characters",
|
'lengthMax' => "must not exceed %d characters",
|
||||||
'instanceOf' => "must be an instance of '%s'",
|
'instanceOf' => "must be an instance of '%s'"
|
||||||
'containsUnique' => "must contain unique elements only",
|
|
||||||
'requiredWith' => "is required",
|
|
||||||
'requiredWithout'=> "is required",
|
|
||||||
'subset' => "contains an item that is not in the list",
|
|
||||||
'arrayHasKeys' => "does not contain all required keys",
|
|
||||||
);
|
);
|
||||||
|
|||||||
@ -30,8 +30,5 @@ return array(
|
|||||||
'creditCard' => "debe ser un numero de tarjeta de crédito válido",
|
'creditCard' => "debe ser un numero de tarjeta de crédito válido",
|
||||||
"lengthMin" => "debe tener al menos %d caracteres",
|
"lengthMin" => "debe tener al menos %d caracteres",
|
||||||
"lengthMax" => "debe tener menos de %d caracteres",
|
"lengthMax" => "debe tener menos de %d caracteres",
|
||||||
"instanceOf" => "debe ser una instancia de '%s'",
|
"instanceOf" => "debe ser una instancia de '%s'"
|
||||||
'containsUnique' => "debe contener solo valores únicos",
|
|
||||||
'subset' => "contiene un elemento que no está en la lista",
|
|
||||||
'arrayHasKeys' => "no contiene todas las claves requeridas"
|
|
||||||
);
|
);
|
||||||
|
|||||||
42
lang/fa.php
42
lang/fa.php
@ -1,42 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
return array(
|
|
||||||
'required' => "الزامی است",
|
|
||||||
'equals' => " باید برابر باشد با '%s'",
|
|
||||||
'different' => "باید متفاوت باشد از '%s'",
|
|
||||||
'accepted' => "باید پذیرفته شده باشد",
|
|
||||||
'numeric' => "باید مقدار عددی باشد",
|
|
||||||
'integer' => "باید عددی طبیعی باشد",
|
|
||||||
'length' => "طول باید %d باشد",
|
|
||||||
'min' => "حداقل باید %s کاراکتر باشد",
|
|
||||||
'max' => "نباید بیشتر از %s کارکتر باشد",
|
|
||||||
'listContains' => "حاوی مقدار نامعتبر",
|
|
||||||
'in' => "حاوی مقدار نامعتبر",
|
|
||||||
'notIn' => "حاوی مقدار نامعتبر",
|
|
||||||
'ip' => " آدرس معتبر نیست IP",
|
|
||||||
'ipv4' => "آدرس معتبر نیست IPv4",
|
|
||||||
'ipv6' => "آدرس معتبر نیست IPv6",
|
|
||||||
'email' => "آدرس ایمیل معتبر نیست",
|
|
||||||
'url' => "معتبر نیست URL",
|
|
||||||
'urlActive' => "دامنه باید فعال باشد",
|
|
||||||
'alpha' => "باید حاوی حروف a-z باشد",
|
|
||||||
'alphaNum' => "باید حاوی حروف a-z و/یا اعداد 0-9 باشد",
|
|
||||||
'slug' => "باید حاوی حروف a-z, اعداد 0-9, دش و آندراسکور باشد",
|
|
||||||
'regex' => "حاوی کارکترهای نامعتبر",
|
|
||||||
'date' => "تاریخ معتبر نیست",
|
|
||||||
'dateFormat' => "فرمت تاریخ باید به این شکل '%s' باشد",
|
|
||||||
'dateBefore' => "تاریخ باید قبل از '%s' باشد",
|
|
||||||
'dateAfter' => "تاریخ باید بعد از '%s' باشد",
|
|
||||||
'contains' => "باید حاوی %s باشد",
|
|
||||||
'boolean' => "مقدار باید بولین باشد",
|
|
||||||
'lengthBetween' => "طول باید بین %d و %d کاراکتر باشد",
|
|
||||||
'creditCard' => "شماره کارت اعتباری معتبر نیست",
|
|
||||||
'lengthMin' => "طول باید حداقل %d کاراکتر باشد",
|
|
||||||
'lengthMax' => "طول نباید بیشتر از %d کاراکتر باشد",
|
|
||||||
'instanceOf' => "باید آبجکتی از نوع '%s' باشد",
|
|
||||||
'containsUnique' => "باید حاوی المان ها یونیک باشد",
|
|
||||||
'requiredWith' => "الزامی است",
|
|
||||||
'requiredWithout'=> "الزامی است",
|
|
||||||
'subset' => "حاوی آیتمی است که در لیست موجود نیست",
|
|
||||||
'arrayHasKeys' => "همه کلیدهای الزامی را ندارد",
|
|
||||||
);
|
|
||||||
@ -10,7 +10,6 @@ return array(
|
|||||||
'length' => "on lyhyempi kuin %d",
|
'length' => "on lyhyempi kuin %d",
|
||||||
'min' => "ei ole vähintään %s",
|
'min' => "ei ole vähintään %s",
|
||||||
'max' => "ei ole enintään %s",
|
'max' => "ei ole enintään %s",
|
||||||
'listContains' => "sisältää virheellisen arvon",
|
|
||||||
'in' => "sisältää virheellisen arvon",
|
'in' => "sisältää virheellisen arvon",
|
||||||
'notIn' => "sisältää virheellisen arvon",
|
'notIn' => "sisältää virheellisen arvon",
|
||||||
'ip' => "ei ole oikeanmuotoinen IP-osoite",
|
'ip' => "ei ole oikeanmuotoinen IP-osoite",
|
||||||
|
|||||||
@ -10,7 +10,6 @@ return array(
|
|||||||
'length' => "doit être plus long que %d",
|
'length' => "doit être plus long que %d",
|
||||||
'min' => "doit être plus grand que %s",
|
'min' => "doit être plus grand que %s",
|
||||||
'max' => "doit être plus petit que %s",
|
'max' => "doit être plus petit que %s",
|
||||||
'listContains' => "contient une valeur non valide",
|
|
||||||
'in' => "contient une valeur non valide",
|
'in' => "contient une valeur non valide",
|
||||||
'notIn' => "contient une valeur non valide",
|
'notIn' => "contient une valeur non valide",
|
||||||
'ip' => "n'est pas une adresse IP valide",
|
'ip' => "n'est pas une adresse IP valide",
|
||||||
@ -31,10 +30,5 @@ return array(
|
|||||||
'creditCard' => "doit être un numéro de carte de crédit valide",
|
'creditCard' => "doit être un numéro de carte de crédit valide",
|
||||||
'lengthMin' => "doit avoir au moins %d caractères",
|
'lengthMin' => "doit avoir au moins %d caractères",
|
||||||
'lengthMax' => "ne doit pas dépasser %d caractères",
|
'lengthMax' => "ne doit pas dépasser %d caractères",
|
||||||
'instanceOf' => "doit être une instance de '%s'",
|
'instanceOf' => "doit être une instance de '%s'"
|
||||||
"containsUnique" => "doit contenir des élements unique",
|
|
||||||
"requiredWith" => "est requis",
|
|
||||||
"requiredWithout" => "est requis",
|
|
||||||
"subset" => "contient un élement qui n'est pas dans la liste",
|
|
||||||
"arrayHasKeys" => "ne contient pas toutes les clés requises"
|
|
||||||
);
|
);
|
||||||
|
|||||||
@ -10,7 +10,6 @@ return array(
|
|||||||
'length' => "harus lebih panjang dari %d",
|
'length' => "harus lebih panjang dari %d",
|
||||||
'min' => "harus lebih besar dari %s",
|
'min' => "harus lebih besar dari %s",
|
||||||
'max' => "harus kurang dari %s",
|
'max' => "harus kurang dari %s",
|
||||||
'listContains' => "berisi nilai/value yang tidak valid",
|
|
||||||
'in' => "berisi nilai/value yang tidak valid",
|
'in' => "berisi nilai/value yang tidak valid",
|
||||||
'notIn' => "berisi nilai/value yang tidak valid",
|
'notIn' => "berisi nilai/value yang tidak valid",
|
||||||
'ip' => "format alamat IP tidak benar",
|
'ip' => "format alamat IP tidak benar",
|
||||||
|
|||||||
@ -10,7 +10,6 @@ return array(
|
|||||||
'length' => "deve avere una lunghezza di %d",
|
'length' => "deve avere una lunghezza di %d",
|
||||||
'min' => "deve essere superiore a %s",
|
'min' => "deve essere superiore a %s",
|
||||||
'max' => "deve essere inferiore a %s",
|
'max' => "deve essere inferiore a %s",
|
||||||
'listContains' => "contiene un valore non valido",
|
|
||||||
'in' => "contiene un valore non valido",
|
'in' => "contiene un valore non valido",
|
||||||
'notIn' => "contiene un valore non valido",
|
'notIn' => "contiene un valore non valido",
|
||||||
'ip' => "non è un indirizzo IP valido",
|
'ip' => "non è un indirizzo IP valido",
|
||||||
|
|||||||
@ -10,12 +10,9 @@ return array(
|
|||||||
'length' => "は%d文字で入力してください",
|
'length' => "は%d文字で入力してください",
|
||||||
'min' => "には%sより大きな値を入力してください",
|
'min' => "には%sより大きな値を入力してください",
|
||||||
'max' => "には%sより小さな値を入力してください",
|
'max' => "には%sより小さな値を入力してください",
|
||||||
'listContains' => "には選択できない値が含まれています",
|
|
||||||
'in' => "には選択できない値が含まれています",
|
'in' => "には選択できない値が含まれています",
|
||||||
'notIn' => "には選択できない値が含まれています",
|
'notIn' => "には選択できない値が含まれています",
|
||||||
'ip' => "はIPアドレスの書式として正しくありません",
|
'ip' => "はIPアドレスの書式として正しくありません",
|
||||||
'ipv4' => "はIPv4のIPアドレスの書式として正しくありません",
|
|
||||||
'ipv6' => "はIPv6のIPアドレスの書式として正しくありません",
|
|
||||||
'email' => "はメールアドレスの書式として正しくありません",
|
'email' => "はメールアドレスの書式として正しくありません",
|
||||||
'url' => "はURLの書式として正しくありません",
|
'url' => "はURLの書式として正しくありません",
|
||||||
'urlActive' => "はアクティブなドメインではありません",
|
'urlActive' => "はアクティブなドメインではありません",
|
||||||
@ -34,9 +31,4 @@ return array(
|
|||||||
'lengthMin' => "は%d文字以上入力してください",
|
'lengthMin' => "は%d文字以上入力してください",
|
||||||
'lengthMax' => "は%d文字以内で入力してください",
|
'lengthMax' => "は%d文字以内で入力してください",
|
||||||
'instanceOf' => "は「%s」のインスタンスではありません",
|
'instanceOf' => "は「%s」のインスタンスではありません",
|
||||||
'containsUnique' => "は重複のないように入力してください",
|
|
||||||
'requiredWith' => "を入力してください",
|
|
||||||
'requiredWithout' => "を入力してください",
|
|
||||||
'subset' => "には選択できない値が含まれています",
|
|
||||||
'arrayHasKeys' => "の必要な項目が選択されていません",
|
|
||||||
);
|
);
|
||||||
|
|||||||
@ -10,7 +10,6 @@ return array(
|
|||||||
'length' => "의 길이는 %d 이어야 합니다.",
|
'length' => "의 길이는 %d 이어야 합니다.",
|
||||||
'min' => "은(는) %s 이상이어야 합니다.",
|
'min' => "은(는) %s 이상이어야 합니다.",
|
||||||
'max' => "은(는) %s 이하여야 합니다.",
|
'max' => "은(는) %s 이하여야 합니다.",
|
||||||
'listContains' => "은(는) 올바르지 않은 값을 포함하고 있습니다.",
|
|
||||||
'in' => "은(는) 올바르지 않은 값을 포함하고 있습니다.",
|
'in' => "은(는) 올바르지 않은 값을 포함하고 있습니다.",
|
||||||
'notIn' => "은(는) 올바르지 않은 값을 포함하고 있습니다.",
|
'notIn' => "은(는) 올바르지 않은 값을 포함하고 있습니다.",
|
||||||
'ip' => "은(는) 올바르지 않은 IP입니다.",
|
'ip' => "은(는) 올바르지 않은 IP입니다.",
|
||||||
|
|||||||
@ -9,12 +9,9 @@ return array(
|
|||||||
'length' => "turi būti %d ženklų ilgio",
|
'length' => "turi būti %d ženklų ilgio",
|
||||||
'min' => "turi būti bent %s",
|
'min' => "turi būti bent %s",
|
||||||
'max' => "turi būti ne daugiau kaip %s",
|
'max' => "turi būti ne daugiau kaip %s",
|
||||||
'listContains' => "turi neteisingą vertę",
|
|
||||||
'in' => "turi neteisingą vertę",
|
'in' => "turi neteisingą vertę",
|
||||||
'notIn' => "turi neteisingą vertę",
|
'notIn' => "turi neteisingą vertę",
|
||||||
'ip' => "nėra teisingas IP adresas",
|
'ip' => "nėra teisingas IP adresas",
|
||||||
'ipv4' => "nėra teisingas IPv4 adresas",
|
|
||||||
'ipv6' => "nėra teisingas IPv6 adresas",
|
|
||||||
'email' => "nėra teisingas el. pašto adresas",
|
'email' => "nėra teisingas el. pašto adresas",
|
||||||
'url' => "nėra teisingas URL",
|
'url' => "nėra teisingas URL",
|
||||||
'urlActive' => "turi būti aktyvus domenas",
|
'urlActive' => "turi būti aktyvus domenas",
|
||||||
@ -32,7 +29,5 @@ return array(
|
|||||||
'creditCard' => "turi būti teisingas kreditinės kortelės numeris",
|
'creditCard' => "turi būti teisingas kreditinės kortelės numeris",
|
||||||
'lengthMin' => "turi būti bent %d ženklų ilgio",
|
'lengthMin' => "turi būti bent %d ženklų ilgio",
|
||||||
'lengthMax' => "turi būti ne ilgesnis nei %d ženklų",
|
'lengthMax' => "turi būti ne ilgesnis nei %d ženklų",
|
||||||
'instanceOf' => "turi būti „%s“ atvejis",
|
'instanceOf' => "turi būti „%s“ atvejis"
|
||||||
'containsUnique' => "turi turėti tik unikalius elementus",
|
|
||||||
'subset' => "turi elementą, kurio nėra sąraše"
|
|
||||||
);
|
);
|
||||||
|
|||||||
@ -10,7 +10,6 @@ return array(
|
|||||||
'length' => "nedrīkst būt garāks par %d simboliem",
|
'length' => "nedrīkst būt garāks par %d simboliem",
|
||||||
'min' => "jābūt garākam par %s simboliem",
|
'min' => "jābūt garākam par %s simboliem",
|
||||||
'max' => "jābūt īsākam par %s simboliem",
|
'max' => "jābūt īsākam par %s simboliem",
|
||||||
'listContains' => "lauks satur nederīgu vērtību",
|
|
||||||
'in' => "lauks satur nederīgu vērtību",
|
'in' => "lauks satur nederīgu vērtību",
|
||||||
'notIn' => "lauks satur nederīgu vērtību",
|
'notIn' => "lauks satur nederīgu vērtību",
|
||||||
'ip' => " lauks nav derīga IP adrese",
|
'ip' => " lauks nav derīga IP adrese",
|
||||||
|
|||||||
39
lang/nb.php
39
lang/nb.php
@ -1,39 +0,0 @@
|
|||||||
<?php
|
|
||||||
// Norwegian Bokmål (nb)
|
|
||||||
return array(
|
|
||||||
'required' => "er påkrevd",
|
|
||||||
'equals' => "må være lik '%s'",
|
|
||||||
'different' => "må være annerledes enn '%s'",
|
|
||||||
'accepted' => "må aksepteres",
|
|
||||||
'numeric' => "må være numerisk",
|
|
||||||
'integer' => "må være et heltall",
|
|
||||||
'length' => "må være %d tegn langt",
|
|
||||||
'min' => "må være minst %s",
|
|
||||||
'max' => "må ikke være mer enn %s",
|
|
||||||
'listContains' => "inneholder ugyldig verdi",
|
|
||||||
'in' => "inneholder ugyldig verdi",
|
|
||||||
'notIn' => "inneholder ugyldig verdi",
|
|
||||||
'ip' => "er ikke en gyldig IP adresse",
|
|
||||||
'ipv4' => "er ikke en gyldig IPv4 adresse",
|
|
||||||
'ipv6' => "er ikke en gyldig IPv6 adresse",
|
|
||||||
'email' => "er ikke en gyldig e-postadresse",
|
|
||||||
'url' => "er ikke en gyldig URL",
|
|
||||||
'urlActive' => "må være et aktivt domene",
|
|
||||||
'alpha' => "må bare innholde bokstaver a-z",
|
|
||||||
'alphaNum' => "må bare innholde bokstaver a-z og/eller tall 0-9",
|
|
||||||
'slug' => "må bare innholde bokstaver a-z og/eller tall 0-9, bindestreker og understreker",
|
|
||||||
'regex' => "inneholder ulovlige tegn",
|
|
||||||
'date' => "er ikke en gyldig dato",
|
|
||||||
'dateFormat' => "må være en dato med format '%s'",
|
|
||||||
'dateBefore' => "må være en dato før '%s'",
|
|
||||||
'dateAfter' => "må være en dato etter '%s'",
|
|
||||||
'contains' => "må inneholde %s",
|
|
||||||
'boolean' => "må være en boolsk verdi",
|
|
||||||
'lengthBetween' => "må være mellom %d og %d tegn",
|
|
||||||
'creditCard' => "må være et gyldig kredittkortnummer",
|
|
||||||
'lengthMin' => "må være minst %d tegn langt",
|
|
||||||
'lengthMax' => "må ikke overstige %d tegn",
|
|
||||||
'instanceOf' => "må være en instans av '%s'",
|
|
||||||
'containsUnique'=> "må inneholde kun unike elementer",
|
|
||||||
'subset' => "inneholder et element som ikke er i listen"
|
|
||||||
);
|
|
||||||
@ -10,7 +10,6 @@ return array(
|
|||||||
'length' => "moet minstens %d karakters lang zijn",
|
'length' => "moet minstens %d karakters lang zijn",
|
||||||
'min' => "moet minstens %s zijn",
|
'min' => "moet minstens %s zijn",
|
||||||
'max' => "mag niet meer zijn dan %s",
|
'max' => "mag niet meer zijn dan %s",
|
||||||
'listContains' => "bevat een ongeldige waarde",
|
|
||||||
'in' => "bevat een ongeldige waarde",
|
'in' => "bevat een ongeldige waarde",
|
||||||
'notIn' => "bevat een ongeldige waarde",
|
'notIn' => "bevat een ongeldige waarde",
|
||||||
'ip' => "is geen geldig IP-adres",
|
'ip' => "is geen geldig IP-adres",
|
||||||
|
|||||||
35
lang/nn.php
35
lang/nn.php
@ -1,35 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
return array(
|
|
||||||
'required' => "er nødvendig",
|
|
||||||
'equals' => "må være de samme som '%s'",
|
|
||||||
'different' => "må være annerledes enn '%s'",
|
|
||||||
'accepted' => "må aksepteres",
|
|
||||||
'numeric' => "må være numerisk",
|
|
||||||
'integer' => "må være et heltall",
|
|
||||||
'length' => "må være %d tegn",
|
|
||||||
'min' => "må være minst %s",
|
|
||||||
'max' => "må ikke være mer enn %s",
|
|
||||||
'listContains' => "inneholder ugyldig verdi",
|
|
||||||
'in' => "inneholder ugyldig verdi",
|
|
||||||
'notIn' => "inneholder ugyldig verdi",
|
|
||||||
'ip' => "er ikkje ein gyldig IP Adresse",
|
|
||||||
'email' => "er ikkje ein gyldig E-post adresse",
|
|
||||||
'url' => "er ikkje ein gyldig URL",
|
|
||||||
'urlActive' => "må være eit aktivt domene",
|
|
||||||
'alpha' => "må bare innholde bokstaver a-z",
|
|
||||||
'alphaNum' => "må bare innholde bokstaver a-z og/eller tall 0-9",
|
|
||||||
'slug' => "må bare innholde bokstaver a-z og/eller tall 0-9, bindestreker og understreker",
|
|
||||||
'regex' => "inneholder ulovlige tegn",
|
|
||||||
'date' => "er ikkje ein gylid dato",
|
|
||||||
'dateFormat' => "må være ein dato med formatet '%s'",
|
|
||||||
'dateBefore' => "må være ein dato før '%s'",
|
|
||||||
'dateAfter' => "må være ein dato etter '%s'",
|
|
||||||
'contains' => "må inneholde %s",
|
|
||||||
'boolean' => "må være ein boolsk verdi",
|
|
||||||
'lengthBetween' => "må være imellom %d og %d tegn",
|
|
||||||
'creditCard' => "må være et gyldig kredittkortnummer",
|
|
||||||
'lengthMin' => "må være minst %d tegn",
|
|
||||||
'lengthMax' => "må ikkje overstige %d tegn",
|
|
||||||
'instanceOf' => "må være ein instans av '%s'"
|
|
||||||
);
|
|
||||||
33
lang/no.php
33
lang/no.php
@ -1,3 +1,34 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
return include __DIR__ . '/nn.php';
|
return array(
|
||||||
|
'required' => "er nødvendig",
|
||||||
|
'equals' => "må være de samme som '%s'",
|
||||||
|
'different' => "må være annerledes enn '%s'",
|
||||||
|
'accepted' => "må aksepteres",
|
||||||
|
'numeric' => "må være numerisk",
|
||||||
|
'integer' => "må være et heltall",
|
||||||
|
'length' => "må være %d tegn",
|
||||||
|
'min' => "må være minst %s",
|
||||||
|
'max' => "må ikke være mer enn %s",
|
||||||
|
'in' => "inneholder ugyldig verdi",
|
||||||
|
'notIn' => "inneholder ugyldig verdi",
|
||||||
|
'ip' => "er ikkje ein gyldig IP Adresse",
|
||||||
|
'email' => "er ikkje ein gyldig E-post adresse",
|
||||||
|
'url' => "er ikkje ein gyldig URL",
|
||||||
|
'urlActive' => "må være eit aktivt domene",
|
||||||
|
'alpha' => "må bare innholde bokstaver a-z",
|
||||||
|
'alphaNum' => "må bare innholde bokstaver a-z og/eller tall 0-9",
|
||||||
|
'slug' => "må bare innholde bokstaver a-z og/eller tall 0-9, bindestreker og understreker",
|
||||||
|
'regex' => "inneholder ulovlige tegn",
|
||||||
|
'date' => "er ikkje ein gylid dato",
|
||||||
|
'dateFormat' => "må være ein dato med formatet '%s'",
|
||||||
|
'dateBefore' => "må være ein dato før '%s'",
|
||||||
|
'dateAfter' => "må være ein dato etter '%s'",
|
||||||
|
'contains' => "må inneholde %s",
|
||||||
|
'boolean' => "må være ein boolsk verdi",
|
||||||
|
'lengthBetween' => "må være imellom %d og %d tegn",
|
||||||
|
'creditCard' => "må være et gyldig kredittkortnummer",
|
||||||
|
'lengthMin' => "må være minst %d tegn",
|
||||||
|
'lengthMax' => "må ikkje overstige %d tegn",
|
||||||
|
'instanceOf' => "må være ein instans av '%s'"
|
||||||
|
);
|
||||||
|
|||||||
@ -10,7 +10,6 @@ return array(
|
|||||||
'length' => "musi być dłuższe niż %d",
|
'length' => "musi być dłuższe niż %d",
|
||||||
'min' => "musi być przynajmniej %s",
|
'min' => "musi być przynajmniej %s",
|
||||||
'max' => "nie może być większe niż %s",
|
'max' => "nie może być większe niż %s",
|
||||||
'listContains' => "zawiera nieprawidłową wartość",
|
|
||||||
'in' => "zawiera nieprawidłową wartość",
|
'in' => "zawiera nieprawidłową wartość",
|
||||||
'notIn' => "zawiera nieprawidłową wartość",
|
'notIn' => "zawiera nieprawidłową wartość",
|
||||||
'ip' => "nie jest prawidłowym adresem IP",
|
'ip' => "nie jest prawidłowym adresem IP",
|
||||||
|
|||||||
@ -30,8 +30,5 @@ return array(
|
|||||||
'creditCard' => "deve ser um numero de cartão de credito válido",
|
'creditCard' => "deve ser um numero de cartão de credito válido",
|
||||||
'lengthMin' => "deve ter ao menos %d caracteres",
|
'lengthMin' => "deve ter ao menos %d caracteres",
|
||||||
'lengthMax' => "não deve exceder %d caracteres",
|
'lengthMax' => "não deve exceder %d caracteres",
|
||||||
'instanceOf' => "deve ser uma instância de '%s'",
|
'instanceOf' => "deve ser uma instância de '%s'"
|
||||||
'containsUnique' => "deve conter apenas valores únicos",
|
|
||||||
'subset' => "contém um item que não está na lista",
|
|
||||||
'arrayHasKeys' => "não contém todas as chaves requeridas"
|
|
||||||
);
|
);
|
||||||
@ -10,7 +10,6 @@ return array(
|
|||||||
'length' => "trebuie sa fie mai lung decat %d",
|
'length' => "trebuie sa fie mai lung decat %d",
|
||||||
'min' => "trebuie sa fie cel putin %s",
|
'min' => "trebuie sa fie cel putin %s",
|
||||||
'max' => "nu trebuie sa fie mai mult de %s",
|
'max' => "nu trebuie sa fie mai mult de %s",
|
||||||
'listContains' => "contine caractere invalide",
|
|
||||||
'in' => "contine caractere invalide",
|
'in' => "contine caractere invalide",
|
||||||
'notIn' => "contine o valoare invalida",
|
'notIn' => "contine o valoare invalida",
|
||||||
'ip' => "nu este o adresa IP valida",
|
'ip' => "nu este o adresa IP valida",
|
||||||
|
|||||||
13
lang/ru.php
13
lang/ru.php
@ -2,20 +2,17 @@
|
|||||||
|
|
||||||
return array(
|
return array(
|
||||||
'required' => "обязательно для заполнения",
|
'required' => "обязательно для заполнения",
|
||||||
'equals' => "должно совпадать со значением '%s'",
|
'equals' => "должно содержать '%s'",
|
||||||
'different' => "должно отличаться от '%s'",
|
'different' => "должно отличаться от '%s'",
|
||||||
'accepted' => "должно быть указано",
|
'accepted' => "должно быть указано",
|
||||||
'numeric' => "должно содержать числовое значение",
|
'numeric' => "должно содержать числовое значение",
|
||||||
'integer' => "должно быть числом",
|
'integer' => "должно быть числом",
|
||||||
'length' => "должно быть длиннее, чем %d",
|
'length' => "должно быть длиннее, чем %d",
|
||||||
'min' => "должно быть не менее, чем %s",
|
'min' => "должно быть больше, чем %s",
|
||||||
'max' => "должно быть не более, чем %s",
|
'max' => "должно быть меньше, чем %s",
|
||||||
'listContains' => "содержит неверное значение",
|
|
||||||
'in' => "содержит неверное значение",
|
'in' => "содержит неверное значение",
|
||||||
'notIn' => "содержит неверное значение",
|
'notIn' => "содержит неверное значение",
|
||||||
'ip' => "не является валидным IP адресом",
|
'ip' => "не является валидным IP адресом",
|
||||||
'ipv4' => "не является валидным IPv4 адресом",
|
|
||||||
'ipv6' => "не является валидным IPv6 адресом",
|
|
||||||
'email' => "не является валидным email адресом",
|
'email' => "не является валидным email адресом",
|
||||||
'url' => "не является валидной ссылкой",
|
'url' => "не является валидной ссылкой",
|
||||||
'urlActive' => "содержит не активную ссылку",
|
'urlActive' => "содержит не активную ссылку",
|
||||||
@ -33,7 +30,5 @@ return array(
|
|||||||
'creditCard' => "должно быть номером кредитной карты",
|
'creditCard' => "должно быть номером кредитной карты",
|
||||||
'lengthMin' => "должно содержать более %d символов",
|
'lengthMin' => "должно содержать более %d символов",
|
||||||
'lengthMax' => "должно содержать менее %d символов",
|
'lengthMax' => "должно содержать менее %d символов",
|
||||||
'instanceOf' => "должно быть объектом класса '%s'",
|
'instanceOf' => "должно быть объектом класса '%s'"
|
||||||
'containsUnique' => "должно содержать только уникальные элементы",
|
|
||||||
'subset' => "содержит элемент, не указанный в списке",
|
|
||||||
);
|
);
|
||||||
|
|||||||
@ -10,7 +10,6 @@ return array(
|
|||||||
'length' => "musí byť dlhý aspoň %d",
|
'length' => "musí byť dlhý aspoň %d",
|
||||||
'min' => "musí byť dlhý minimálne %s",
|
'min' => "musí byť dlhý minimálne %s",
|
||||||
'max' => "musí byť maximálne %s",
|
'max' => "musí byť maximálne %s",
|
||||||
'listContains' => "obsahuje nepovolenú hodnotu",
|
|
||||||
'in' => "obsahuje nepovolenú hodnotu",
|
'in' => "obsahuje nepovolenú hodnotu",
|
||||||
'notIn' => "obsahuje nepovolenú hodnotu",
|
'notIn' => "obsahuje nepovolenú hodnotu",
|
||||||
'ip' => "nie je korektná IP adresa",
|
'ip' => "nie je korektná IP adresa",
|
||||||
|
|||||||
42
lang/sl.php
42
lang/sl.php
@ -1,42 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
return array(
|
|
||||||
'required' => "potrebno",
|
|
||||||
'equals' => "mora biti enak '% s'",
|
|
||||||
'different' => "mora biti drugačen od '% s'",
|
|
||||||
'accepted' => "mora biti označeno",
|
|
||||||
'numeric' => "mora biti številka",
|
|
||||||
'integer' => "mora biti celo število",
|
|
||||||
'length' => "ne sme biti daljši od% d",
|
|
||||||
'min' => "mora biti večji od% s",
|
|
||||||
'max' => "mora biti manjši od% s",
|
|
||||||
'listContains' => "vsebuje neveljavno vrednost",
|
|
||||||
'in' => "vsebuje neveljavno vrednost",
|
|
||||||
'notIn' => "vsebuje neveljavno vrednost",
|
|
||||||
'ip' => "ni veljaven naslov IP",
|
|
||||||
'ipv4' => "ni veljaven naslov IPv4",
|
|
||||||
'ipv6' => "ni veljaven naslov IPv6",
|
|
||||||
'email' => "ni veljaven e-poštni naslov",
|
|
||||||
'url' => "ni veljaven URL",
|
|
||||||
'urlActive' => "mora biti aktivna domena",
|
|
||||||
'alpha' => "mora vsebovati samo črke a-z",
|
|
||||||
'alphaNum' => "mora vsebovati samo črke a-z in / ali številke 0-9",
|
|
||||||
'slug' => "mora vsebovati samo črke a-z, številke 0-9, črtice in podčrtaje",
|
|
||||||
'regex' => "vsebuje neveljavne znake",
|
|
||||||
'date' => "ni veljaven datum",
|
|
||||||
'dateFormat' => "mora biti datum s formatom '% s'",
|
|
||||||
'dateBefore' => "mora biti datum pred '% s'",
|
|
||||||
'dateAfter' => "mora biti datum za '% s'",
|
|
||||||
'contains' => "mora vsebovati% s",
|
|
||||||
'boolean' => "mora biti boolean",
|
|
||||||
'lengthBetween' => "mora biti med% d in% d znaki",
|
|
||||||
'creditCard' => "mora biti veljavna številka kreditne kartice",
|
|
||||||
'lengthMin' => "mora biti dolg vsaj% d znakov",
|
|
||||||
'lengthMax' => "ne sme presegati% d znakov",
|
|
||||||
'instanceOf' => "mora biti primerek '% s'",
|
|
||||||
'containsUnique' => "mora vsebovati samo edinstvene elemente",
|
|
||||||
'requiredWith' => "je potrebno",
|
|
||||||
'requiredWithout'=> "je potrebno",
|
|
||||||
'subset' => "vsebuje element, ki ga ni na seznamu",
|
|
||||||
'arrayHasKeys' => "ne vsebuje vseh potrebnih tipk",
|
|
||||||
);
|
|
||||||
21
lang/sv.php
21
lang/sv.php
@ -10,26 +10,25 @@ return array(
|
|||||||
'length' => "måste vara %d tecken långt",
|
'length' => "måste vara %d tecken långt",
|
||||||
'min' => "måste vara minst %s",
|
'min' => "måste vara minst %s",
|
||||||
'max' => "får inte vara mer än %s",
|
'max' => "får inte vara mer än %s",
|
||||||
'listContains' => "innehåller ogiltigt värde",
|
|
||||||
'in' => "innehåller ogiltigt värde",
|
'in' => "innehåller ogiltigt värde",
|
||||||
'notIn' => "innehåller ogiltigt värde",
|
'notIn' => "innehåller ogiltigt värde",
|
||||||
'ip' => "är inte en giltig IP-adress",
|
'ip' => "är inte en giltlig IP-adress",
|
||||||
'email' => "är inte en giltig e-postadress",
|
'email' => "är inte en giltlig e-postadress",
|
||||||
'url' => "är inte en giltig URL",
|
'url' => "är inte en giltlig URL",
|
||||||
'urlActive' => "måste vara ett aktivt domännamn",
|
'urlActive' => "måste vara ett aktivt domännamn",
|
||||||
'alpha' => "får bara innehålla bokstäver a-z",
|
'alpha' => "får bara inehålla bokstäver a-z",
|
||||||
'alphaNum' => "får bara innehålla bokstäver a-z och/eller siffror 0-9",
|
'alphaNum' => "får bara inehålla bokstäver a-z och/eller siffror 0-9",
|
||||||
'slug' => "får bara innehålla bokstäver a-z och/eller siffror 0-9, bindesstreck och understreck",
|
'slug' => "får bara inehålla bokstäver a-z och/eller siffror 0-9, bindesträck og understräck",
|
||||||
'regex' => "innehåller ogiltiga tecken",
|
'regex' => "inehåller ogiltliga tecken",
|
||||||
'date' => "är inte ett giltigt datum",
|
'date' => "är inte ett giltligt datum",
|
||||||
'dateFormat' => "måste vara ett datum med formatet '%s'",
|
'dateFormat' => "måste vara ett datum med formatet '%s'",
|
||||||
'dateBefore' => "måste vara ett datum före '%s'",
|
'dateBefore' => "måste vara ett datum före '%s'",
|
||||||
'dateAfter' => "måste vara ett datum efter '%s'",
|
'dateAfter' => "måste vara ett datum efter '%s'",
|
||||||
'contains' => "måste innehålla %s",
|
'contains' => "måste innehålla %s",
|
||||||
'boolean' => "måste vara ett booleskt värde",
|
'boolean' => "måste vara ett booleskt värde",
|
||||||
'lengthBetween' => "måste vara mellan %d och %d tecken långt",
|
'lengthBetween' => "måste vara mellan %d och %d tecken långt",
|
||||||
'creditCard' => "måste vara ett giltigt kreditkortsnummer",
|
'creditCard' => "måste vara et gyldig kredittkortnummer",
|
||||||
'lengthMin' => "måste vara minst %d tecken långt",
|
'lengthMin' => "måste vara minst %d tecken långt",
|
||||||
'lengthMax' => "får inte överstiga %d tecken",
|
'lengthMax' => "får itne överstiga %d tecken",
|
||||||
'instanceOf' => "måste vara en instans av '%s'"
|
'instanceOf' => "måste vara en instans av '%s'"
|
||||||
);
|
);
|
||||||
|
|||||||
@ -10,7 +10,6 @@ return array(
|
|||||||
'length' => "ต้องมีความยาวมากกว่า %d",
|
'length' => "ต้องมีความยาวมากกว่า %d",
|
||||||
'min' => "ต้องมีอย่างน้อย %s",
|
'min' => "ต้องมีอย่างน้อย %s",
|
||||||
'max' => "ต้องไม่มากเกิน %s",
|
'max' => "ต้องไม่มากเกิน %s",
|
||||||
'listContains' => "ประกอบด้วยค่าที่ไม่ถูกต้อง",
|
|
||||||
'in' => "ประกอบด้วยค่าที่ไม่ถูกต้อง",
|
'in' => "ประกอบด้วยค่าที่ไม่ถูกต้อง",
|
||||||
'notIn' => "ประกอบด้วยค่าที่ไม่ถูกต้อง",
|
'notIn' => "ประกอบด้วยค่าที่ไม่ถูกต้อง",
|
||||||
'ip' => "ไม่ใช่ IP ที่ถูกต้อง",
|
'ip' => "ไม่ใช่ IP ที่ถูกต้อง",
|
||||||
|
|||||||
@ -10,7 +10,6 @@ return array(
|
|||||||
'length' => "en az %d adet uzunluğunda olmalı",
|
'length' => "en az %d adet uzunluğunda olmalı",
|
||||||
'min' => "en az böyle olmalı %s",
|
'min' => "en az böyle olmalı %s",
|
||||||
'max' => "bundan daha fazla olmalı %s",
|
'max' => "bundan daha fazla olmalı %s",
|
||||||
'listContains' => "geçersiz değer içeriyor",
|
|
||||||
'in' => "geçersiz değer içeriyor",
|
'in' => "geçersiz değer içeriyor",
|
||||||
'notIn' => "geçersiz değer içeriyor",
|
'notIn' => "geçersiz değer içeriyor",
|
||||||
'ip' => "geçerli bir IP adresi değil",
|
'ip' => "geçerli bir IP adresi değil",
|
||||||
@ -29,7 +28,7 @@ return array(
|
|||||||
'boolean' => "boolean olmalı",
|
'boolean' => "boolean olmalı",
|
||||||
'lengthBetween' => "%d ve %d karakter arasında olmalı",
|
'lengthBetween' => "%d ve %d karakter arasında olmalı",
|
||||||
'creditCard' => "geçerli bir kredi kartı numarası olmalı",
|
'creditCard' => "geçerli bir kredi kartı numarası olmalı",
|
||||||
"lengthMin" => "%d karakterden fazla içermeli",
|
"lengthMin" => "%d katakterden fazla içermeli",
|
||||||
"lengthMax" => "%d karakterden az içermeli",
|
"lengthMax" => "%d karakterden az içermeli",
|
||||||
"instanceOf" => "bunun bir örneği olmalı '%s'"
|
"instanceOf" => "bunun bir örneği olmalı '%s'"
|
||||||
);
|
);
|
||||||
|
|||||||
@ -10,7 +10,6 @@ return array(
|
|||||||
'length' => "має бути довшим, ніж %d",
|
'length' => "має бути довшим, ніж %d",
|
||||||
'min' => "має бути більше, ніж %s",
|
'min' => "має бути більше, ніж %s",
|
||||||
'max' => "повинно бути менше, ніж %s",
|
'max' => "повинно бути менше, ніж %s",
|
||||||
'listContains' => "містить невірне значення",
|
|
||||||
'in' => "містить невірне значення",
|
'in' => "містить невірне значення",
|
||||||
'notIn' => "містить невірне значення",
|
'notIn' => "містить невірне значення",
|
||||||
'ip' => "не є валідною IP адресою",
|
'ip' => "не є валідною IP адресою",
|
||||||
|
|||||||
@ -10,7 +10,6 @@ return array(
|
|||||||
'length' => "phải dài hơn %d",
|
'length' => "phải dài hơn %d",
|
||||||
'min' => "ít nhất %s",
|
'min' => "ít nhất %s",
|
||||||
'max' => "tối đa %s",
|
'max' => "tối đa %s",
|
||||||
'listContains' => "chứa giá trị không hợp lệ",
|
|
||||||
'in' => "chứa giá trị không hợp lệ",
|
'in' => "chứa giá trị không hợp lệ",
|
||||||
'notIn' => "chứa giá trị không hợp lệ",
|
'notIn' => "chứa giá trị không hợp lệ",
|
||||||
'ip' => "địa chỉ IP không hợp lệ",
|
'ip' => "địa chỉ IP không hợp lệ",
|
||||||
|
|||||||
@ -7,10 +7,9 @@ return array(
|
|||||||
'accepted' => "必须接受",
|
'accepted' => "必须接受",
|
||||||
'numeric' => "只能是数字",
|
'numeric' => "只能是数字",
|
||||||
'integer' => "只能是整数",
|
'integer' => "只能是整数",
|
||||||
'length' => "长度必须等于 %d",
|
'length' => "长度必须大于 %d",
|
||||||
'min' => "必须大于 %s",
|
'min' => "必须大于 %s",
|
||||||
'max' => "必须小于 %s",
|
'max' => "必须小于 %s",
|
||||||
'listContains' => "无效的值",
|
|
||||||
'in' => "无效的值",
|
'in' => "无效的值",
|
||||||
'notIn' => "无效的值",
|
'notIn' => "无效的值",
|
||||||
'ip' => "无效IP地址",
|
'ip' => "无效IP地址",
|
||||||
@ -30,11 +29,5 @@ return array(
|
|||||||
'lengthBetween' => "长度只能介于 %d 和 %d 之间",
|
'lengthBetween' => "长度只能介于 %d 和 %d 之间",
|
||||||
'creditCard' => "信用卡号码不正确",
|
'creditCard' => "信用卡号码不正确",
|
||||||
'lengthMin' => "长度必须大于 %d",
|
'lengthMin' => "长度必须大于 %d",
|
||||||
'lengthMax' => "长度必须小于 %d",
|
'lengthMax' => "长度必须小于 %d"
|
||||||
'instanceOf' => "必须是 '%s' 的实例",
|
|
||||||
'containsUnique' => "必须仅包含唯一的元素",
|
|
||||||
'requiredWith' => "是必须的",
|
|
||||||
'requiredWithout' => "是必须的",
|
|
||||||
'subset' => "包含不在列表中的项目",
|
|
||||||
'arrayHasKeys' => "不包含所有必需的键",
|
|
||||||
);
|
);
|
||||||
|
|||||||
@ -10,7 +10,6 @@ return array(
|
|||||||
'length' => "長度必須大於 %d",
|
'length' => "長度必須大於 %d",
|
||||||
'min' => "必須大於 %s",
|
'min' => "必須大於 %s",
|
||||||
'max' => "必須小於 %s",
|
'max' => "必須小於 %s",
|
||||||
'listContains' => "無效的值",
|
|
||||||
'in' => "無效的值",
|
'in' => "無效的值",
|
||||||
'notIn' => "無效的值",
|
'notIn' => "無效的值",
|
||||||
'ip' => "無效IP地址",
|
'ip' => "無效IP地址",
|
||||||
@ -25,16 +24,5 @@ return array(
|
|||||||
'dateFormat' => "日期的格式應該為 '%s'",
|
'dateFormat' => "日期的格式應該為 '%s'",
|
||||||
'dateBefore' => "日期必須在 '%s' 之前",
|
'dateBefore' => "日期必須在 '%s' 之前",
|
||||||
'dateAfter' => "日期必須在 '%s' 之後",
|
'dateAfter' => "日期必須在 '%s' 之後",
|
||||||
'contains' => "必須包含 %s",
|
'contains' => "必須包含 %s"
|
||||||
'boolean' => "必須是真或假",
|
|
||||||
'lengthBetween' => "長度只能介於 %d 和 %d 之間",
|
|
||||||
'creditCard' => "信用卡號碼不正確",
|
|
||||||
'lengthMin' => "長度必須大於 %d",
|
|
||||||
'lengthMax' => "長度必須小於 %d",
|
|
||||||
'instanceOf' => "必須是 '%s' 的實例",
|
|
||||||
'containsUnique' => "必須僅包含唯一的元素",
|
|
||||||
'requiredWith' => "是必須的",
|
|
||||||
'requiredWithout' => "是必須的",
|
|
||||||
'subset' => "包含不在列表中的項目",
|
|
||||||
'arrayHasKeys' => "不包含所有必需的鍵",
|
|
||||||
);
|
);
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
convertWarningsToExceptions="true"
|
convertWarningsToExceptions="true"
|
||||||
processIsolation="false"
|
processIsolation="false"
|
||||||
stopOnFailure="false"
|
stopOnFailure="false"
|
||||||
|
syntaxCheck="false"
|
||||||
bootstrap="tests/bootstrap.php"
|
bootstrap="tests/bootstrap.php"
|
||||||
>
|
>
|
||||||
<testsuites>
|
<testsuites>
|
||||||
@ -14,4 +15,12 @@
|
|||||||
<directory suffix="Test.php">tests/Valitron</directory>
|
<directory suffix="Test.php">tests/Valitron</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
|
<filter>
|
||||||
|
<whitelist>
|
||||||
|
<directory suffix=".php">src/</directory>
|
||||||
|
</whitelist>
|
||||||
|
<blacklist>
|
||||||
|
<directory suffix=".php">vendor/</directory>
|
||||||
|
</blacklist>
|
||||||
|
</filter>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Valitron;
|
namespace Valitron;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -83,11 +82,6 @@ class Validator
|
|||||||
*/
|
*/
|
||||||
protected $stop_on_first_fail = false;
|
protected $stop_on_first_fail = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
protected $prepend_labels = true;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup validation
|
* Setup validation
|
||||||
*
|
*
|
||||||
@ -111,7 +105,7 @@ class Validator
|
|||||||
|
|
||||||
// Load language file in directory
|
// Load language file in directory
|
||||||
$langFile = rtrim($langDir, '/') . '/' . $lang . '.php';
|
$langFile = rtrim($langDir, '/') . '/' . $lang . '.php';
|
||||||
if (stream_resolve_include_path($langFile)) {
|
if (stream_resolve_include_path($langFile) ) {
|
||||||
$langMessages = include $langFile;
|
$langMessages = include $langFile;
|
||||||
static::$_ruleMessages = array_merge(static::$_ruleMessages, $langMessages);
|
static::$_ruleMessages = array_merge(static::$_ruleMessages, $langMessages);
|
||||||
} else {
|
} else {
|
||||||
@ -149,14 +143,6 @@ class Validator
|
|||||||
return static::$_langDir ?: dirname(dirname(__DIR__)) . '/lang';
|
return static::$_langDir ?: dirname(dirname(__DIR__)) . '/lang';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param bool $prepend_labels
|
|
||||||
*/
|
|
||||||
public function setPrependLabels($prepend_labels = true)
|
|
||||||
{
|
|
||||||
$this->prepend_labels = $prepend_labels;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Required field validator
|
* Required field validator
|
||||||
*
|
*
|
||||||
@ -165,14 +151,16 @@ class Validator
|
|||||||
* @param array $params
|
* @param array $params
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function validateRequired($field, $value, $params = array())
|
protected function validateRequired($field, $value, $params= array())
|
||||||
{
|
{
|
||||||
if (isset($params[0]) && (bool)$params[0]) {
|
if (isset($params[0]) && (bool) $params[0]){
|
||||||
$find = $this->getPart($this->_fields, explode('.', $field), true);
|
$find = $this->getPart($this->_fields, explode('.', $field), true);
|
||||||
return $find[1];
|
return $find[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($value) || (is_string($value) && trim($value) === '')) {
|
if (is_null($value)) {
|
||||||
|
return false;
|
||||||
|
} elseif (is_string($value) && trim($value) === '') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,6 +173,7 @@ class Validator
|
|||||||
* @param string $field
|
* @param string $field
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $params
|
* @param array $params
|
||||||
|
* @internal param array $fields
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function validateEquals($field, $value, array $params)
|
protected function validateEquals($field, $value, array $params)
|
||||||
@ -200,6 +189,7 @@ class Validator
|
|||||||
* @param string $field
|
* @param string $field
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $params
|
* @param array $params
|
||||||
|
* @internal param array $fields
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function validateDifferent($field, $value, array $params)
|
protected function validateDifferent($field, $value, array $params)
|
||||||
@ -259,7 +249,7 @@ class Validator
|
|||||||
*/
|
*/
|
||||||
protected function validateInteger($field, $value, $params)
|
protected function validateInteger($field, $value, $params)
|
||||||
{
|
{
|
||||||
if (isset($params[0]) && (bool)$params[0]) {
|
if (isset($params[0]) && (bool) $params[0]){
|
||||||
//strict mode
|
//strict mode
|
||||||
return preg_match('/^([0-9]|-[1-9]|-?[1-9][0-9]*)$/i', $value);
|
return preg_match('/^([0-9]|-[1-9]|-?[1-9][0-9]*)$/i', $value);
|
||||||
}
|
}
|
||||||
@ -273,6 +263,7 @@ class Validator
|
|||||||
* @param string $field
|
* @param string $field
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $params
|
* @param array $params
|
||||||
|
* @internal param array $fields
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function validateLength($field, $value, $params)
|
protected function validateLength($field, $value, $params)
|
||||||
@ -292,7 +283,7 @@ class Validator
|
|||||||
* @param string $field
|
* @param string $field
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $params
|
* @param array $params
|
||||||
* @return bool
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
protected function validateLengthBetween($field, $value, $params)
|
protected function validateLengthBetween($field, $value, $params)
|
||||||
{
|
{
|
||||||
@ -308,7 +299,7 @@ class Validator
|
|||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $params
|
* @param array $params
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
protected function validateLengthMin($field, $value, $params)
|
protected function validateLengthMin($field, $value, $params)
|
||||||
{
|
{
|
||||||
@ -324,7 +315,7 @@ class Validator
|
|||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $params
|
* @param array $params
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
protected function validateLengthMax($field, $value, $params)
|
protected function validateLengthMax($field, $value, $params)
|
||||||
{
|
{
|
||||||
@ -356,6 +347,7 @@ class Validator
|
|||||||
* @param string $field
|
* @param string $field
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $params
|
* @param array $params
|
||||||
|
* @internal param array $fields
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function validateMin($field, $value, $params)
|
protected function validateMin($field, $value, $params)
|
||||||
@ -375,6 +367,7 @@ class Validator
|
|||||||
* @param string $field
|
* @param string $field
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $params
|
* @param array $params
|
||||||
|
* @internal param array $fields
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function validateMax($field, $value, $params)
|
protected function validateMax($field, $value, $params)
|
||||||
@ -394,6 +387,7 @@ class Validator
|
|||||||
* @param string $field
|
* @param string $field
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $params
|
* @param array $params
|
||||||
|
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function validateBetween($field, $value, $params)
|
protected function validateBetween($field, $value, $params)
|
||||||
@ -416,16 +410,13 @@ class Validator
|
|||||||
* @param string $field
|
* @param string $field
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $params
|
* @param array $params
|
||||||
|
* @internal param array $fields
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function validateIn($field, $value, $params)
|
protected function validateIn($field, $value, $params)
|
||||||
{
|
{
|
||||||
$forceAsAssociative = false;
|
$isAssoc = array_values($params[0]) !== $params[0];
|
||||||
if (isset($params[2])) {
|
if ($isAssoc) {
|
||||||
$forceAsAssociative = (bool) $params[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($forceAsAssociative || $this->isAssociativeArray($params[0])) {
|
|
||||||
$params[0] = array_keys($params[0]);
|
$params[0] = array_keys($params[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -437,39 +428,13 @@ class Validator
|
|||||||
return in_array($value, $params[0], $strict);
|
return in_array($value, $params[0], $strict);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate a field is contained within a list of values
|
|
||||||
*
|
|
||||||
* @param string $field
|
|
||||||
* @param mixed $value
|
|
||||||
* @param array $params
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function validateListContains($field, $value, $params)
|
|
||||||
{
|
|
||||||
$forceAsAssociative = false;
|
|
||||||
if (isset($params[2])) {
|
|
||||||
$forceAsAssociative = (bool) $params[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($forceAsAssociative || $this->isAssociativeArray($value)) {
|
|
||||||
$value = array_keys($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
$strict = false;
|
|
||||||
if (isset($params[1])) {
|
|
||||||
$strict = $params[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
return in_array($params[0], $value, $strict);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate a field is not contained within a list of values
|
* Validate a field is not contained within a list of values
|
||||||
*
|
*
|
||||||
* @param string $field
|
* @param string $field
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $params
|
* @param array $params
|
||||||
|
* @internal param array $fields
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function validateNotIn($field, $value, $params)
|
protected function validateNotIn($field, $value, $params)
|
||||||
@ -481,7 +446,7 @@ class Validator
|
|||||||
* Validate a field contains a given string
|
* Validate a field contains a given string
|
||||||
*
|
*
|
||||||
* @param string $field
|
* @param string $field
|
||||||
* @param string $value
|
* @param mixed $value
|
||||||
* @param array $params
|
* @param array $params
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@ -496,9 +461,10 @@ class Validator
|
|||||||
|
|
||||||
$strict = true;
|
$strict = true;
|
||||||
if (isset($params[1])) {
|
if (isset($params[1])) {
|
||||||
$strict = (bool)$params[1];
|
$strict = (bool) $params[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$isContains = false;
|
||||||
if ($strict) {
|
if ($strict) {
|
||||||
if (function_exists('mb_strpos')) {
|
if (function_exists('mb_strpos')) {
|
||||||
$isContains = mb_strpos($value, $params[0]) !== false;
|
$isContains = mb_strpos($value, $params[0]) !== false;
|
||||||
@ -515,46 +481,6 @@ class Validator
|
|||||||
return $isContains;
|
return $isContains;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate that all field values contains a given array
|
|
||||||
*
|
|
||||||
* @param string $field
|
|
||||||
* @param array $value
|
|
||||||
* @param array $params
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function validateSubset($field, $value, $params)
|
|
||||||
{
|
|
||||||
if (!isset($params[0])) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!is_array($params[0])) {
|
|
||||||
$params[0] = array($params[0]);
|
|
||||||
}
|
|
||||||
if (is_scalar($value) || is_null($value)) {
|
|
||||||
return $this->validateIn($field, $value, $params);
|
|
||||||
}
|
|
||||||
|
|
||||||
$intersect = array_intersect($value, $params[0]);
|
|
||||||
return array_diff($value, $intersect) === array_diff($intersect, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate that field array has only unique values
|
|
||||||
*
|
|
||||||
* @param string $field
|
|
||||||
* @param array $value
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function validateContainsUnique($field, $value)
|
|
||||||
{
|
|
||||||
if (!is_array($value)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $value === array_unique($value, SORT_REGULAR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate that a field is a valid IP address
|
* Validate that a field is a valid IP address
|
||||||
*
|
*
|
||||||
@ -567,30 +493,6 @@ class Validator
|
|||||||
return filter_var($value, \FILTER_VALIDATE_IP) !== false;
|
return filter_var($value, \FILTER_VALIDATE_IP) !== false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate that a field is a valid IP v4 address
|
|
||||||
*
|
|
||||||
* @param string $field
|
|
||||||
* @param mixed $value
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function validateIpv4($field, $value)
|
|
||||||
{
|
|
||||||
return filter_var($value, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4) !== false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate that a field is a valid IP v6 address
|
|
||||||
*
|
|
||||||
* @param string $field
|
|
||||||
* @param mixed $value
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function validateIpv6($field, $value)
|
|
||||||
{
|
|
||||||
return filter_var($value, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6) !== false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate that a field is a valid e-mail address
|
* Validate that a field is a valid e-mail address
|
||||||
*
|
*
|
||||||
@ -603,24 +505,6 @@ class Validator
|
|||||||
return filter_var($value, \FILTER_VALIDATE_EMAIL) !== false;
|
return filter_var($value, \FILTER_VALIDATE_EMAIL) !== false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate that a field contains only ASCII characters
|
|
||||||
*
|
|
||||||
* @param $field
|
|
||||||
* @param $value
|
|
||||||
* @return bool|false|string
|
|
||||||
*/
|
|
||||||
protected function validateAscii($field, $value)
|
|
||||||
{
|
|
||||||
// multibyte extension needed
|
|
||||||
if (function_exists('mb_detect_encoding')) {
|
|
||||||
return mb_detect_encoding($value, 'ASCII', true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// fallback with regex
|
|
||||||
return 0 === preg_match('/[^\x00-\x7F]/', $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate that a field is a valid e-mail address and the domain name is active
|
* Validate that a field is a valid e-mail address and the domain name is active
|
||||||
*
|
*
|
||||||
@ -630,17 +514,12 @@ class Validator
|
|||||||
*/
|
*/
|
||||||
protected function validateEmailDNS($field, $value)
|
protected function validateEmailDNS($field, $value)
|
||||||
{
|
{
|
||||||
if (!is_string($value)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->validateEmail($field, $value)) {
|
if ($this->validateEmail($field, $value)) {
|
||||||
$domain = ltrim(stristr($value, '@'), '@') . '.';
|
$domain = ltrim(stristr($value, '@'), '@') . '.';
|
||||||
if (function_exists('idn_to_ascii') && defined('INTL_IDNA_VARIANT_UTS46')) {
|
if (function_exists('idn_to_ascii') && defined('INTL_IDNA_VARIANT_UTS46')) {
|
||||||
$domain = idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46);
|
$domain = idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46);
|
||||||
}
|
}
|
||||||
|
return checkdnsrr($domain, 'ANY');
|
||||||
return checkdnsrr($domain, 'MX');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -655,10 +534,6 @@ class Validator
|
|||||||
*/
|
*/
|
||||||
protected function validateUrl($field, $value)
|
protected function validateUrl($field, $value)
|
||||||
{
|
{
|
||||||
if (!is_string($value)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->validUrlPrefixes as $prefix) {
|
foreach ($this->validUrlPrefixes as $prefix) {
|
||||||
if (strpos($value, $prefix) !== false) {
|
if (strpos($value, $prefix) !== false) {
|
||||||
return filter_var($value, \FILTER_VALIDATE_URL) !== false;
|
return filter_var($value, \FILTER_VALIDATE_URL) !== false;
|
||||||
@ -677,10 +552,6 @@ class Validator
|
|||||||
*/
|
*/
|
||||||
protected function validateUrlActive($field, $value)
|
protected function validateUrlActive($field, $value)
|
||||||
{
|
{
|
||||||
if (!is_string($value)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->validUrlPrefixes as $prefix) {
|
foreach ($this->validUrlPrefixes as $prefix) {
|
||||||
if (strpos($value, $prefix) !== false) {
|
if (strpos($value, $prefix) !== false) {
|
||||||
$host = parse_url(strtolower($value), PHP_URL_HOST);
|
$host = parse_url(strtolower($value), PHP_URL_HOST);
|
||||||
@ -725,7 +596,7 @@ class Validator
|
|||||||
*/
|
*/
|
||||||
protected function validateSlug($field, $value)
|
protected function validateSlug($field, $value)
|
||||||
{
|
{
|
||||||
if (is_array($value)) {
|
if(is_array($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return preg_match('/^([-a-z0-9_-])+$/i', $value);
|
return preg_match('/^([-a-z0-9_-])+$/i', $value);
|
||||||
@ -769,6 +640,7 @@ class Validator
|
|||||||
* @param string $field
|
* @param string $field
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $params
|
* @param array $params
|
||||||
|
* @internal param array $fields
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function validateDateFormat($field, $value, $params)
|
protected function validateDateFormat($field, $value, $params)
|
||||||
@ -784,6 +656,7 @@ class Validator
|
|||||||
* @param string $field
|
* @param string $field
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $params
|
* @param array $params
|
||||||
|
* @internal param array $fields
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function validateDateBefore($field, $value, $params)
|
protected function validateDateBefore($field, $value, $params)
|
||||||
@ -800,6 +673,7 @@ class Validator
|
|||||||
* @param string $field
|
* @param string $field
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $params
|
* @param array $params
|
||||||
|
* @internal param array $fields
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function validateDateAfter($field, $value, $params)
|
protected function validateDateAfter($field, $value, $params)
|
||||||
@ -867,7 +741,7 @@ class Validator
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for ($i = 0; $i < $strlen; $i++) {
|
for ($i = 0; $i < $strlen; $i++) {
|
||||||
$digit = (int)substr($number, $strlen - $i - 1, 1);
|
$digit = (int) substr($number, $strlen - $i - 1, 1);
|
||||||
if ($i % 2 == 1) {
|
if ($i % 2 == 1) {
|
||||||
$sub_total = $digit * 2;
|
$sub_total = $digit * 2;
|
||||||
if ($sub_total > 9) {
|
if ($sub_total > 9) {
|
||||||
@ -909,11 +783,13 @@ class Validator
|
|||||||
} elseif (isset($cards)) {
|
} elseif (isset($cards)) {
|
||||||
// if we have cards, check our users card against only the ones we have
|
// if we have cards, check our users card against only the ones we have
|
||||||
foreach ($cards as $card) {
|
foreach ($cards as $card) {
|
||||||
if (in_array($card, array_keys($cardRegex)) && preg_match($cardRegex[$card], $value) === 1) {
|
if (in_array($card, array_keys($cardRegex))) {
|
||||||
// if the card is valid, we want to stop looping
|
// if the card is valid, we want to stop looping
|
||||||
|
if (preg_match($cardRegex[$card], $value) === 1) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// loop through every card
|
// loop through every card
|
||||||
foreach ($cardRegex as $regex) {
|
foreach ($cardRegex as $regex) {
|
||||||
@ -950,125 +826,12 @@ class Validator
|
|||||||
return $isInstanceOf;
|
return $isInstanceOf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
//Validate optional field
|
||||||
* Validates whether or not a field is required based on whether or not other fields are present.
|
protected function validateOptional($field, $value, $params) {
|
||||||
*
|
|
||||||
* @param string $field name of the field in the data array
|
|
||||||
* @param mixed $value value of this field
|
|
||||||
* @param array $params parameters for this rule
|
|
||||||
* @param array $fields full list of data to be validated
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function validateRequiredWith($field, $value, $params, $fields)
|
|
||||||
{
|
|
||||||
$conditionallyReq = false;
|
|
||||||
// if we actually have conditionally required with fields to check against
|
|
||||||
if (isset($params[0])) {
|
|
||||||
// convert single value to array if it isn't already
|
|
||||||
$reqParams = is_array($params[0]) ? $params[0] : array($params[0]);
|
|
||||||
// check for the flag indicating if all fields are required
|
|
||||||
$allRequired = isset($params[1]) && (bool)$params[1];
|
|
||||||
$emptyFields = 0;
|
|
||||||
foreach ($reqParams as $requiredField) {
|
|
||||||
// check the field is set, not null, and not the empty string
|
|
||||||
list($requiredFieldValue, $multiple) = $this->getPart($fields, explode('.', $requiredField));
|
|
||||||
if (isset($requiredFieldValue) && (!is_string($requiredFieldValue) || trim($requiredFieldValue) !== '')) {
|
|
||||||
if (!$allRequired) {
|
|
||||||
$conditionallyReq = true;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
$emptyFields++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// if all required fields are present in strict mode, we're requiring it
|
|
||||||
if ($allRequired && $emptyFields === count($reqParams)) {
|
|
||||||
$conditionallyReq = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// if we have conditionally required fields
|
|
||||||
if ($conditionallyReq && (is_null($value) ||
|
|
||||||
is_string($value) && trim($value) === '')) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validates whether or not a field is required based on whether or not other fields are present.
|
|
||||||
*
|
|
||||||
* @param string $field name of the field in the data array
|
|
||||||
* @param mixed $value value of this field
|
|
||||||
* @param array $params parameters for this rule
|
|
||||||
* @param array $fields full list of data to be validated
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function validateRequiredWithout($field, $value, $params, $fields)
|
|
||||||
{
|
|
||||||
$conditionallyReq = false;
|
|
||||||
// if we actually have conditionally required with fields to check against
|
|
||||||
if (isset($params[0])) {
|
|
||||||
// convert single value to array if it isn't already
|
|
||||||
$reqParams = is_array($params[0]) ? $params[0] : array($params[0]);
|
|
||||||
// check for the flag indicating if all fields are required
|
|
||||||
$allEmpty = isset($params[1]) && (bool)$params[1];
|
|
||||||
$filledFields = 0;
|
|
||||||
foreach ($reqParams as $requiredField) {
|
|
||||||
// check the field is NOT set, null, or the empty string, in which case we are requiring this value be present
|
|
||||||
list($requiredFieldValue, $multiple) = $this->getPart($fields, explode('.', $requiredField));
|
|
||||||
if (!isset($requiredFieldValue) || (is_string($requiredFieldValue) && trim($requiredFieldValue) === '')) {
|
|
||||||
if (!$allEmpty) {
|
|
||||||
$conditionallyReq = true;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
$filledFields++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// if all fields were empty, then we're requiring this in strict mode
|
|
||||||
if ($allEmpty && $filledFields === count($reqParams)) {
|
|
||||||
$conditionallyReq = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// if we have conditionally required fields
|
|
||||||
if ($conditionallyReq && (is_null($value) ||
|
|
||||||
is_string($value) && trim($value) === '')) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate optional field
|
|
||||||
*
|
|
||||||
* @param $field
|
|
||||||
* @param $value
|
|
||||||
* @param $params
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function validateOptional($field, $value, $params)
|
|
||||||
{
|
|
||||||
//Always return true
|
//Always return true
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function validateArrayHasKeys($field, $value, $params)
|
|
||||||
{
|
|
||||||
if (!is_array($value) || !isset($params[0])) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$requiredFields = $params[0];
|
|
||||||
if (count($requiredFields) === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
foreach ($requiredFields as $fieldName) {
|
|
||||||
if (!array_key_exists($fieldName, $value)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get array of fields and data
|
* Get array of fields and data
|
||||||
*
|
*
|
||||||
@ -1098,12 +861,12 @@ class Validator
|
|||||||
* Add an error to error messages array
|
* Add an error to error messages array
|
||||||
*
|
*
|
||||||
* @param string $field
|
* @param string $field
|
||||||
* @param string $message
|
* @param string $msg
|
||||||
* @param array $params
|
* @param array $params
|
||||||
*/
|
*/
|
||||||
public function error($field, $message, array $params = array())
|
public function error($field, $msg, array $params = array())
|
||||||
{
|
{
|
||||||
$message = $this->checkAndSetLabel($field, $message, $params);
|
$msg = $this->checkAndSetLabel($field, $msg, $params);
|
||||||
|
|
||||||
$values = array();
|
$values = array();
|
||||||
// Printed values need to be in string format
|
// Printed values need to be in string format
|
||||||
@ -1119,24 +882,26 @@ class Validator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Use custom label instead of field name if set
|
// Use custom label instead of field name if set
|
||||||
if (is_string($params[0]) && isset($this->_labels[$param])) {
|
if (is_string($params[0])) {
|
||||||
|
if (isset($this->_labels[$param])) {
|
||||||
$param = $this->_labels[$param];
|
$param = $this->_labels[$param];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
$values[] = $param;
|
$values[] = $param;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->_errors[$field][] = vsprintf($message, $values);
|
$this->_errors[$field][] = vsprintf($msg, $values);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify validation message to use for error for the last validation rule
|
* Specify validation message to use for error for the last validation rule
|
||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $msg
|
||||||
* @return Validator
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function message($message)
|
public function message($msg)
|
||||||
{
|
{
|
||||||
$this->_validations[count($this->_validations) - 1]['message'] = $message;
|
$this->_validations[count($this->_validations) - 1]['message'] = $msg;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -1160,7 +925,7 @@ class Validator
|
|||||||
}
|
}
|
||||||
// Catches the case where the data isn't an array or object
|
// Catches the case where the data isn't an array or object
|
||||||
if (is_scalar($data)) {
|
if (is_scalar($data)) {
|
||||||
return array(null, false);
|
return array(NULL, false);
|
||||||
}
|
}
|
||||||
$identifier = array_shift($identifiers);
|
$identifier = array_shift($identifiers);
|
||||||
// Glob match
|
// Glob match
|
||||||
@ -1175,60 +940,49 @@ class Validator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return array($values, true);
|
return array($values, true);
|
||||||
} // Dead end, abort
|
}
|
||||||
elseif ($identifier === null || ! isset($data[$identifier])) {
|
// Dead end, abort
|
||||||
|
elseif ($identifier === NULL || ! isset($data[$identifier])) {
|
||||||
if ($allow_empty){
|
if ($allow_empty){
|
||||||
//when empty values are allowed, we only care if the key exists
|
//when empty values are allowed, we only care if the key exists
|
||||||
return array(null, array_key_exists($identifier, $data));
|
return array(null, array_key_exists($identifier, $data));
|
||||||
}
|
}
|
||||||
return array(null, false);
|
return array(null, false);
|
||||||
} // Match array element
|
}
|
||||||
|
// Match array element
|
||||||
elseif (count($identifiers) === 0) {
|
elseif (count($identifiers) === 0) {
|
||||||
if ($allow_empty) {
|
if ($allow_empty){
|
||||||
//when empty values are allowed, we only care if the key exists
|
//when empty values are allowed, we only care if the key exists
|
||||||
return array(null, array_key_exists($identifier, $data));
|
return array(null, array_key_exists($identifier, $data));
|
||||||
}
|
}
|
||||||
return array($data[$identifier], $allow_empty);
|
return array($data[$identifier], false);
|
||||||
} // We need to go deeper
|
}
|
||||||
|
// We need to go deeper
|
||||||
else {
|
else {
|
||||||
return $this->getPart($data[$identifier], $identifiers, $allow_empty);
|
return $this->getPart($data[$identifier], $identifiers, $allow_empty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function validationMustBeExcecuted($validation, $field, $values, $multiple){
|
|
||||||
//always excecute requiredWith(out) rules
|
|
||||||
if (in_array($validation['rule'], array('requiredWith', 'requiredWithout'))){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//do not execute if the field is optional and not set
|
|
||||||
if($this->hasRule('optional', $field) && ! isset($values)){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//ignore empty input, except for required and accepted rule
|
|
||||||
if (! $this->hasRule('required', $field) && ! in_array($validation['rule'], array('required', 'accepted'))){
|
|
||||||
if($multiple){
|
|
||||||
return count($values) != 0;
|
|
||||||
}
|
|
||||||
return (isset($values) && $values !== '');
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Run validations and return boolean result
|
* Run validations and return boolean result
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function validate()
|
public function validate()
|
||||||
{
|
{
|
||||||
$set_to_break = false;
|
$set_to_break = false;
|
||||||
foreach ($this->_validations as $v) {
|
foreach ($this->_validations as $v) {
|
||||||
foreach ($v['fields'] as $field) {
|
foreach ($v['fields'] as $field) {
|
||||||
list($values, $multiple) = $this->getPart($this->_fields, explode('.', $field), false);
|
list($values, $multiple) = $this->getPart($this->_fields, explode('.', $field));
|
||||||
|
|
||||||
if (! $this->validationMustBeExcecuted($v, $field, $values, $multiple)){
|
// Don't validate if the field is not required and the value is empty
|
||||||
|
if ($this->hasRule('optional', $field) && isset($values)) {
|
||||||
|
//Continue with execution below if statement
|
||||||
|
} elseif (
|
||||||
|
$v['rule'] !== 'required' && !$this->hasRule('required', $field) &&
|
||||||
|
$v['rule'] !== 'accepted' &&
|
||||||
|
(! isset($values) || $values === '' || ($multiple && count($values) == 0))
|
||||||
|
) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1242,8 +996,6 @@ class Validator
|
|||||||
|
|
||||||
if (!$multiple) {
|
if (!$multiple) {
|
||||||
$values = array($values);
|
$values = array($values);
|
||||||
} else if (! $this->hasRule('required', $field)){
|
|
||||||
$values = array_filter($values);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = true;
|
$result = true;
|
||||||
@ -1253,15 +1005,13 @@ class Validator
|
|||||||
|
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
$this->error($field, $v['message'], $v['params']);
|
$this->error($field, $v['message'], $v['params']);
|
||||||
if ($this->stop_on_first_fail) {
|
if($this->stop_on_first_fail) {
|
||||||
$set_to_break = true;
|
$set_to_break = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($set_to_break) {
|
if($set_to_break) break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return count($this->errors()) === 0;
|
return count($this->errors()) === 0;
|
||||||
@ -1271,9 +1021,8 @@ class Validator
|
|||||||
* Should the validation stop a rule is failed
|
* Should the validation stop a rule is failed
|
||||||
* @param bool $stop
|
* @param bool $stop
|
||||||
*/
|
*/
|
||||||
public function stopOnFirstFail($stop = true)
|
public function stopOnFirstFail($stop = true) {
|
||||||
{
|
$this->stop_on_first_fail = (bool) $stop;
|
||||||
$this->stop_on_first_fail = (bool)$stop;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1301,15 +1050,18 @@ class Validator
|
|||||||
*
|
*
|
||||||
* @param string $name The name of the rule
|
* @param string $name The name of the rule
|
||||||
* @param string $field The name of the field
|
* @param string $field The name of the field
|
||||||
* @return bool
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected function hasRule($name, $field)
|
protected function hasRule($name, $field)
|
||||||
{
|
{
|
||||||
foreach ($this->_validations as $validation) {
|
foreach ($this->_validations as $validation) {
|
||||||
if ($validation['rule'] == $name && in_array($field, $validation['fields'])) {
|
if ($validation['rule'] == $name) {
|
||||||
|
if (in_array($field, $validation['fields'])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1317,18 +1069,17 @@ class Validator
|
|||||||
protected static function assertRuleCallback($callback)
|
protected static function assertRuleCallback($callback)
|
||||||
{
|
{
|
||||||
if (!is_callable($callback)) {
|
if (!is_callable($callback)) {
|
||||||
throw new \InvalidArgumentException(
|
throw new \InvalidArgumentException('Second argument must be a valid callback. Given argument was not callable.');
|
||||||
'Second argument must be a valid callback. Given argument was not callable.'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a new validation rule callback that is tied to the current
|
* Adds a new validation rule callback that is tied to the current
|
||||||
* instance only.
|
* instance only.
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param callable $callback
|
* @param mixed $callback
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
@ -1344,13 +1095,14 @@ class Validator
|
|||||||
* Register new validation rule callback
|
* Register new validation rule callback
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param callable $callback
|
* @param mixed $callback
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public static function addRule($name, $callback, $message = null)
|
public static function addRule($name, $callback, $message = null)
|
||||||
{
|
{
|
||||||
if ($message === null) {
|
if ($message === null)
|
||||||
|
{
|
||||||
$message = static::ERROR_DEFAULT;
|
$message = static::ERROR_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1360,20 +1112,18 @@ class Validator
|
|||||||
static::$_ruleMessages[$name] = $message;
|
static::$_ruleMessages[$name] = $message;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param mixed $fields
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getUniqueRuleName($fields)
|
public function getUniqueRuleName($fields)
|
||||||
{
|
{
|
||||||
if (is_array($fields)) {
|
if (is_array($fields))
|
||||||
|
{
|
||||||
$fields = implode("_", $fields);
|
$fields = implode("_", $fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
$orgName = "{$fields}_rule";
|
$orgName = "{$fields}_rule";
|
||||||
$name = $orgName;
|
$name = $orgName;
|
||||||
$rules = $this->getRules();
|
$rules = $this->getRules();
|
||||||
while (isset($rules[$name])) {
|
while (isset($rules[$name]))
|
||||||
|
{
|
||||||
$name = $orgName . "_" . rand(0, 10000);
|
$name = $orgName . "_" . rand(0, 10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1397,9 +1147,9 @@ class Validator
|
|||||||
/**
|
/**
|
||||||
* Convenience method to add a single validation rule
|
* Convenience method to add a single validation rule
|
||||||
*
|
*
|
||||||
* @param string|callable $rule
|
* @param string|callback $rule
|
||||||
* @param array|string $fields
|
* @param array|string $fields
|
||||||
* @return Validator
|
* @return $this
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function rule($rule, $fields)
|
public function rule($rule, $fields)
|
||||||
@ -1408,10 +1158,11 @@ class Validator
|
|||||||
$params = array_slice(func_get_args(), 2);
|
$params = array_slice(func_get_args(), 2);
|
||||||
|
|
||||||
if (is_callable($rule)
|
if (is_callable($rule)
|
||||||
&& !(is_string($rule) && $this->hasValidator($rule))) {
|
&& !(is_string($rule) && $this->hasValidator($rule)))
|
||||||
|
{
|
||||||
$name = $this->getUniqueRuleName($fields);
|
$name = $this->getUniqueRuleName($fields);
|
||||||
$message = isset($params[0]) ? $params[0] : null;
|
$msg = isset($params[0]) ? $params[0] : null;
|
||||||
$this->addInstanceRule($name, $rule, $message);
|
$this->addInstanceRule($name, $rule, $msg);
|
||||||
$rule = $name;
|
$rule = $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1419,15 +1170,13 @@ class Validator
|
|||||||
if (!isset($errors[$rule])) {
|
if (!isset($errors[$rule])) {
|
||||||
$ruleMethod = 'validate' . ucfirst($rule);
|
$ruleMethod = 'validate' . ucfirst($rule);
|
||||||
if (!method_exists($this, $ruleMethod)) {
|
if (!method_exists($this, $ruleMethod)) {
|
||||||
throw new \InvalidArgumentException(
|
throw new \InvalidArgumentException("Rule '" . $rule . "' has not been registered with " . __CLASS__ . "::addRule().");
|
||||||
"Rule '" . $rule . "' has not been registered with " . get_called_class() . "::addRule()."
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure rule has an accompanying message
|
// Ensure rule has an accompanying message
|
||||||
$messages = $this->getRuleMessages();
|
$msgs = $this->getRuleMessages();
|
||||||
$message = isset($messages[$rule]) ? $messages[$rule] : self::ERROR_DEFAULT;
|
$message = isset($msgs[$rule]) ? $msgs[$rule] : self::ERROR_DEFAULT;
|
||||||
|
|
||||||
// Ensure message contains field label
|
// Ensure message contains field label
|
||||||
if (function_exists('mb_strpos')) {
|
if (function_exists('mb_strpos')) {
|
||||||
@ -1441,8 +1190,8 @@ class Validator
|
|||||||
|
|
||||||
$this->_validations[] = array(
|
$this->_validations[] = array(
|
||||||
'rule' => $rule,
|
'rule' => $rule,
|
||||||
'fields' => (array)$fields,
|
'fields' => (array) $fields,
|
||||||
'params' => (array)$params,
|
'params' => (array) $params,
|
||||||
'message' => $message
|
'message' => $message
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -1453,7 +1202,8 @@ class Validator
|
|||||||
* Add label to rule
|
* Add label to rule
|
||||||
*
|
*
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @return Validator
|
* @internal param array $labels
|
||||||
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function label($value)
|
public function label($value)
|
||||||
{
|
{
|
||||||
@ -1467,7 +1217,7 @@ class Validator
|
|||||||
* Add labels to rules
|
* Add labels to rules
|
||||||
*
|
*
|
||||||
* @param array $labels
|
* @param array $labels
|
||||||
* @return Validator
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function labels($labels = array())
|
public function labels($labels = array())
|
||||||
{
|
{
|
||||||
@ -1478,31 +1228,29 @@ class Validator
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $field
|
* @param string $field
|
||||||
* @param string $message
|
* @param string $msg
|
||||||
* @param array $params
|
* @param array $params
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function checkAndSetLabel($field, $message, $params)
|
protected function checkAndSetLabel($field, $msg, $params)
|
||||||
{
|
{
|
||||||
if (isset($this->_labels[$field])) {
|
if (isset($this->_labels[$field])) {
|
||||||
$message = str_replace('{field}', $this->_labels[$field], $message);
|
$msg = str_replace('{field}', $this->_labels[$field], $msg);
|
||||||
|
|
||||||
if (is_array($params)) {
|
if (is_array($params)) {
|
||||||
$i = 1;
|
$i = 1;
|
||||||
foreach ($params as $k => $v) {
|
foreach ($params as $k => $v) {
|
||||||
$tag = '{field' . $i . '}';
|
$tag = '{field'. $i .'}';
|
||||||
$label = isset($params[$k]) && (is_numeric($params[$k]) || is_string($params[$k])) && isset($this->_labels[$params[$k]]) ? $this->_labels[$params[$k]] : $tag;
|
$label = isset($params[$k]) && (is_numeric($params[$k]) || is_string($params[$k])) && isset($this->_labels[$params[$k]]) ? $this->_labels[$params[$k]] : $tag;
|
||||||
$message = str_replace($tag, $label, $message);
|
$msg = str_replace($tag, $label, $msg);
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$message = $this->prepend_labels
|
$msg = str_replace('{field}', ucwords(str_replace('_', ' ', $field)), $msg);
|
||||||
? str_replace('{field}', ucwords(str_replace('_', ' ', $field)), $message)
|
|
||||||
: str_replace('{field} ', '', $message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $message;
|
return $msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1515,8 +1263,8 @@ class Validator
|
|||||||
foreach ($rules as $ruleType => $params) {
|
foreach ($rules as $ruleType => $params) {
|
||||||
if (is_array($params)) {
|
if (is_array($params)) {
|
||||||
foreach ($params as $innerParams) {
|
foreach ($params as $innerParams) {
|
||||||
if (!is_array($innerParams)) {
|
if (! is_array($innerParams)){
|
||||||
$innerParams = (array)$innerParams;
|
$innerParams = (array) $innerParams;
|
||||||
}
|
}
|
||||||
array_unshift($innerParams, $ruleType);
|
array_unshift($innerParams, $ruleType);
|
||||||
call_user_func_array(array($this, 'rule'), $innerParams);
|
call_user_func_array(array($this, 'rule'), $innerParams);
|
||||||
@ -1532,7 +1280,7 @@ class Validator
|
|||||||
*
|
*
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @param array $fields
|
* @param array $fields
|
||||||
* @return Validator
|
* @return \Valitron\Validator
|
||||||
*/
|
*/
|
||||||
public function withData($data, $fields = array())
|
public function withData($data, $fields = array())
|
||||||
{
|
{
|
||||||
@ -1545,33 +1293,32 @@ class Validator
|
|||||||
/**
|
/**
|
||||||
* Convenience method to add validation rule(s) by field
|
* Convenience method to add validation rule(s) by field
|
||||||
*
|
*
|
||||||
* @param string $field
|
* @param string field_name
|
||||||
* @param array $rules
|
* @param array $rules
|
||||||
*/
|
*/
|
||||||
public function mapFieldRules($field, $rules)
|
public function mapFieldRules($field_name, $rules){
|
||||||
{
|
|
||||||
$me = $this;
|
$me = $this;
|
||||||
|
|
||||||
array_map(function ($rule) use ($field, $me) {
|
array_map(function($rule) use($field_name, $me){
|
||||||
|
|
||||||
//rule must be an array
|
//rule must be an array
|
||||||
$rule = (array)$rule;
|
$rule = (array)$rule;
|
||||||
|
|
||||||
//First element is the name of the rule
|
//First element is the name of the rule
|
||||||
$ruleName = array_shift($rule);
|
$rule_name = array_shift($rule);
|
||||||
|
|
||||||
//find a custom message, if any
|
//find a custom message, if any
|
||||||
$message = null;
|
$message = null;
|
||||||
if (isset($rule['message'])) {
|
if (isset($rule['message'])){
|
||||||
$message = $rule['message'];
|
$message = $rule['message'];
|
||||||
unset($rule['message']);
|
unset($rule['message']);
|
||||||
}
|
}
|
||||||
//Add the field and additional parameters to the rule
|
//Add the field and additional parameters to the rule
|
||||||
$added = call_user_func_array(array($me, 'rule'), array_merge(array($ruleName, $field), $rule));
|
$added = call_user_func_array(array($me, 'rule'), array_merge(array($rule_name, $field_name), $rule));
|
||||||
if (!empty($message)) {
|
if (! empty($message)){
|
||||||
$added->message($message);
|
$added->message($message);
|
||||||
}
|
}
|
||||||
}, (array)$rules);
|
}, (array) $rules);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1579,16 +1326,10 @@ class Validator
|
|||||||
*
|
*
|
||||||
* @param array $rules
|
* @param array $rules
|
||||||
*/
|
*/
|
||||||
public function mapFieldsRules($rules)
|
public function mapFieldsRules($rules){
|
||||||
{
|
|
||||||
$me = $this;
|
$me = $this;
|
||||||
array_map(function ($field) use ($rules, $me) {
|
array_map(function($field_name) use($rules, $me){
|
||||||
$me->mapFieldRules($field, $rules[$field]);
|
$me->mapFieldRules($field_name, $rules[$field_name]);
|
||||||
}, array_keys($rules));
|
}, array_keys($rules));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function isAssociativeArray($input){
|
|
||||||
//array contains at least one key that's not an can not be cast to an integer
|
|
||||||
return count(array_filter(array_keys($input), 'is_string')) > 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,8 +4,10 @@ use PHPUnit\Framework\TestCase;
|
|||||||
|
|
||||||
class BaseTestCase extends TestCase
|
class BaseTestCase extends TestCase
|
||||||
{
|
{
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
public function tearDown()
|
public function tearDown()
|
||||||
{
|
{
|
||||||
$this->resetProperty('_lang');
|
$this->resetProperty('_lang');
|
||||||
@ -16,10 +18,9 @@ class BaseTestCase extends TestCase
|
|||||||
|
|
||||||
protected function resetProperty($name, $value = null)
|
protected function resetProperty($name, $value = null)
|
||||||
{
|
{
|
||||||
$prop = new \ReflectionProperty('Valitron\Validator', $name);
|
$prop = new ReflectionProperty('Valitron\Validator', $name);
|
||||||
$prop->setAccessible(true);
|
$prop->setAccessible(true);
|
||||||
$prop->setValue($value);
|
$prop->setValue($value);
|
||||||
$prop->setAccessible(false);
|
$prop->setAccessible(false);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Valitron\Validator;
|
use Valitron\Validator;
|
||||||
|
|
||||||
class ErrorMessagesTest extends BaseTestCase
|
class ErrorMessagesTest extends BaseTestCase
|
||||||
@ -12,19 +11,6 @@ class ErrorMessagesTest extends BaseTestCase
|
|||||||
$this->assertSame(array("Name is required"), $v->errors('name'));
|
$this->assertSame(array("Name is required"), $v->errors('name'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Test the disabling of prepending the field labels
|
|
||||||
* to error messages.
|
|
||||||
*/
|
|
||||||
public function testErrorMessageExcludeFieldName()
|
|
||||||
{
|
|
||||||
$v = new Validator(array());
|
|
||||||
$v->setPrependLabels(false);
|
|
||||||
$v->rule('required', 'name');
|
|
||||||
$v->validate();
|
|
||||||
$this->assertSame(array("is required"), $v->errors('name'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testAccurateErrorMessageParams()
|
public function testAccurateErrorMessageParams()
|
||||||
{
|
{
|
||||||
$v = new Validator(array('num' => 5));
|
$v = new Validator(array('num' => 5));
|
||||||
@ -74,18 +60,17 @@ class ErrorMessagesTest extends BaseTestCase
|
|||||||
|
|
||||||
public function testMessageWithFieldSet()
|
public function testMessageWithFieldSet()
|
||||||
{
|
{
|
||||||
$v = new Validator(array('name' => ''), array(), 'en', __DIR__ . '/../lang');
|
$v = new Validator(array('name'=>''), array(), 'en', __DIR__ . '/../lang');
|
||||||
$v->rule('required', 'name');
|
$v->rule('required', 'name');
|
||||||
$v->validate();
|
$v->validate();
|
||||||
$this->assertEquals($v->errors('name'), array('A value is required for Name'));
|
$this->assertEquals( $v->errors('name'), array('A value is required for Name'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMessageWithFieldAndLabelSet()
|
public function testMessageWithFieldAndLabelSet(){
|
||||||
{
|
$v = new Validator(array('name'=>''), array(), 'en', __DIR__ . '/../lang');
|
||||||
$v = new Validator(array('name' => ''), array(), 'en', __DIR__ . '/../lang');
|
|
||||||
$v->rule('required', 'name')->label('my name');
|
$v->rule('required', 'name')->label('my name');
|
||||||
$v->validate();
|
$v->validate();
|
||||||
$this->assertEquals($v->errors('name'), array('A value is required for my name'));
|
$this->assertEquals( $v->errors('name'), array('A value is required for my name'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -9,18 +9,18 @@ class LangTest extends BaseTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lang defined statically should not be override by constructor default
|
* Lang defined statically should not be overrided by constructor default
|
||||||
*/
|
*/
|
||||||
public function testLangDefinedStatically()
|
public function testLangDefinedStatically()
|
||||||
{
|
{
|
||||||
$lang = 'ar';
|
$lang = 'ar';
|
||||||
Validator::lang($lang);
|
Validator::lang($lang);
|
||||||
|
$validator = new Validator(array());
|
||||||
$this->assertEquals($lang, Validator::lang());
|
$this->assertEquals($lang, Validator::lang());
|
||||||
Validator::lang('en');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LangDir defined statically should not be override by constructor default
|
* LangDir defined statically should not be overrided by constructor default
|
||||||
*/
|
*/
|
||||||
public function testLangDirDefinedStatically()
|
public function testLangDirDefinedStatically()
|
||||||
{
|
{
|
||||||
@ -42,23 +42,12 @@ class LangTest extends BaseTestCase
|
|||||||
$this->assertEquals(realpath($this->getLangDir()), realpath(Validator::langDir()));
|
$this->assertEquals(realpath($this->getLangDir()), realpath(Validator::langDir()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException InvalidArgumentException
|
||||||
|
* @expectedExceptionMessage Fail to load language file '/this/dir/does/not/exists/en.php'
|
||||||
|
*/
|
||||||
public function testLangException()
|
public function testLangException()
|
||||||
{
|
{
|
||||||
try{
|
|
||||||
new Validator(array(), array(), 'en', '/this/dir/does/not/exists');
|
new Validator(array(), array(), 'en', '/this/dir/does/not/exists');
|
||||||
} catch (Exception $exception){
|
|
||||||
$this->assertInstanceOf("InvalidArgumentException", $exception);
|
|
||||||
$this->assertEquals("Fail to load language file '/this/dir/does/not/exists/en.php'", $exception->getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function testLoadingNorwegianLoadsNNVariant(){
|
|
||||||
$validator = new Validator(array(), array(),'no', $this->getLangDir());
|
|
||||||
$validator->rule('required','test');
|
|
||||||
$validator->validate();
|
|
||||||
$errors =$validator->errors('test');
|
|
||||||
$this->assertEquals('Test er nødvendig', $errors[0]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Valitron\Validator;
|
use Valitron\Validator;
|
||||||
|
|
||||||
|
|
||||||
class MapRulesTest extends BaseTestCase
|
class MapRulesTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
public function testMapSingleFieldRules()
|
public function testMapSingleFieldRules()
|
||||||
{
|
{
|
||||||
|
|
||||||
$rules = array(
|
$rules = array(
|
||||||
'required',
|
'required',
|
||||||
array('lengthMin', 4)
|
array('lengthMin', 4)
|
||||||
@ -23,6 +24,7 @@ class MapRulesTest extends BaseTestCase
|
|||||||
|
|
||||||
public function testSingleFieldDot()
|
public function testSingleFieldDot()
|
||||||
{
|
{
|
||||||
|
|
||||||
$v = new Valitron\Validator(array(
|
$v = new Valitron\Validator(array(
|
||||||
'settings' => array(
|
'settings' => array(
|
||||||
array('threshold' => 50),
|
array('threshold' => 50),
|
||||||
@ -34,6 +36,7 @@ class MapRulesTest extends BaseTestCase
|
|||||||
));
|
));
|
||||||
|
|
||||||
$this->assertFalse($v->validate());
|
$this->assertFalse($v->validate());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMapMultipleFieldsRules()
|
public function testMapMultipleFieldsRules()
|
||||||
@ -57,6 +60,7 @@ class MapRulesTest extends BaseTestCase
|
|||||||
$this->assertFalse($v->validate());
|
$this->assertFalse($v->validate());
|
||||||
$this->assertFalse($v->errors('myField1'));
|
$this->assertFalse($v->errors('myField1'));
|
||||||
$this->assertEquals(2, sizeof($v->errors('myField2')));
|
$this->assertEquals(2, sizeof($v->errors('myField2')));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCustomMessageSingleField()
|
public function testCustomMessageSingleField()
|
||||||
@ -78,10 +82,10 @@ class MapRulesTest extends BaseTestCase
|
|||||||
{
|
{
|
||||||
$rules = array(
|
$rules = array(
|
||||||
'myField1' => array(
|
'myField1' => array(
|
||||||
array('lengthMin', 14, 'message' => 'My Custom Error 1')
|
array('lengthMin', 14, 'message'=>'My Custom Error 1')
|
||||||
),
|
),
|
||||||
'myField2' => array(
|
'myField2' => array(
|
||||||
array('lengthMin', 14, 'message' => 'My Custom Error 2')
|
array('lengthMin', 14, 'message'=>'My Custom Error 2')
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -96,6 +100,8 @@ class MapRulesTest extends BaseTestCase
|
|||||||
$errors1 = $v->errors('myField1');
|
$errors1 = $v->errors('myField1');
|
||||||
$this->assertEquals('My Custom Error 1', $errors1[0]);
|
$this->assertEquals('My Custom Error 1', $errors1[0]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$errors2 = $v->errors('myField2');
|
$errors2 = $v->errors('myField2');
|
||||||
$this->assertEquals('My Custom Error 2', $errors2[0]);
|
$this->assertEquals('My Custom Error 2', $errors2[0]);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,10 +7,8 @@ class StaticVsInstanceTest extends BaseTestCase
|
|||||||
{
|
{
|
||||||
Validator::lang('ar');
|
Validator::lang('ar');
|
||||||
new Validator(array(), array(), 'en');
|
new Validator(array(), array(), 'en');
|
||||||
$this->assertEquals(
|
$this->assertEquals('ar', Validator::lang(),
|
||||||
'ar', Validator::lang(), 'instance defined lang should not replace static global lang'
|
'instance defined lang should not replace static global lang');
|
||||||
);
|
|
||||||
Validator::lang('en');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,14 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Valitron\Validator;
|
use Valitron\Validator;
|
||||||
|
|
||||||
class StopOnFirstFail extends BaseTestCase
|
|
||||||
{
|
class StopOnFirstFail extends BaseTestCase {
|
||||||
public function testStopOnFirstFail()
|
|
||||||
{
|
public function testStopOnFirstFail() {
|
||||||
$rules = array(
|
$rules = array(
|
||||||
'myField1' => array(
|
'myField1' => array(
|
||||||
array('lengthMin', 5, 'message' => 'myField1 must be 5 characters minimum'),
|
array('lengthMin', 5, 'message'=>'myField1 must be 5 characters minimum'),
|
||||||
array('url', 'message' => 'myField1 is not a valid url'),
|
array('url', 'message' => 'myField1 is not a valid url'),
|
||||||
array('urlActive', 'message' => 'myField1 is not an active url')
|
array('urlActive', 'message' => 'myField1 is not an active url')
|
||||||
)
|
)
|
||||||
@ -25,4 +24,5 @@ class StopOnFirstFail extends BaseTestCase
|
|||||||
$errors = $v->errors();
|
$errors = $v->errors();
|
||||||
$this->assertCount(1, $errors['myField1']);
|
$this->assertCount(1, $errors['myField1']);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Valitron\Validator;
|
use Valitron\Validator;
|
||||||
|
|
||||||
function callbackTestFunction($item, $value)
|
function callbackTestFunction($item, $value)
|
||||||
@ -9,15 +8,14 @@ function callbackTestFunction($item, $value)
|
|||||||
|
|
||||||
class ValidateAddInstanceRuleTest extends BaseTestCase
|
class ValidateAddInstanceRuleTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @param Validator $v
|
|
||||||
*/
|
|
||||||
protected function assertValid($v)
|
protected function assertValid($v)
|
||||||
{
|
{
|
||||||
$msg = "\tErrors:\n";
|
$msg = "\tErrors:\n";
|
||||||
$status = $v->validate();
|
$status = $v->validate();
|
||||||
foreach ($v->errors() as $label => $messages) {
|
foreach ($v->errors() as $label => $messages)
|
||||||
foreach ($messages as $theMessage) {
|
{
|
||||||
|
foreach ($messages as $theMessage)
|
||||||
|
{
|
||||||
$msg .= "\n\t{$label}: {$theMessage}";
|
$msg .= "\n\t{$label}: {$theMessage}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -32,11 +30,13 @@ class ValidateAddInstanceRuleTest extends BaseTestCase
|
|||||||
"fuzz" => "bazz",
|
"fuzz" => "bazz",
|
||||||
));
|
));
|
||||||
|
|
||||||
$v->addInstanceRule("fooRule", function ($field, $value) {
|
$v->addInstanceRule("fooRule", function($field, $value)
|
||||||
|
{
|
||||||
return $field !== "foo" || $value !== "barz";
|
return $field !== "foo" || $value !== "barz";
|
||||||
});
|
});
|
||||||
|
|
||||||
Validator::addRule("fuzzerRule", function ($field, $value) {
|
Validator::addRule("fuzzerRule", function($field, $value)
|
||||||
|
{
|
||||||
return $field !== "fuzz" || $value === "bazz";
|
return $field !== "fuzz" || $value === "bazz";
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -50,7 +50,8 @@ class ValidateAddInstanceRuleTest extends BaseTestCase
|
|||||||
public function testAddInstanceRuleFail()
|
public function testAddInstanceRuleFail()
|
||||||
{
|
{
|
||||||
$v = new Validator(array("foo" => "bar"));
|
$v = new Validator(array("foo" => "bar"));
|
||||||
$v->addInstanceRule("fooRule", function ($field) {
|
$v->addInstanceRule("fooRule", function($field)
|
||||||
|
{
|
||||||
return $field === "for";
|
return $field === "for";
|
||||||
});
|
});
|
||||||
$v->rule("fooRule", "foo");
|
$v->rule("fooRule", "foo");
|
||||||
@ -60,7 +61,7 @@ class ValidateAddInstanceRuleTest extends BaseTestCase
|
|||||||
public function testAddAddRuleWithCallback()
|
public function testAddAddRuleWithCallback()
|
||||||
{
|
{
|
||||||
$v = new Validator(array("foo" => "bar"));
|
$v = new Validator(array("foo" => "bar"));
|
||||||
$v->rule(function ($field, $value) {
|
$v->rule(function($field, $value) {
|
||||||
return $field === "foo" && $value === "bar";
|
return $field === "foo" && $value === "bar";
|
||||||
}, "foo");
|
}, "foo");
|
||||||
|
|
||||||
@ -70,7 +71,7 @@ class ValidateAddInstanceRuleTest extends BaseTestCase
|
|||||||
public function testAddAddRuleWithCallbackFail()
|
public function testAddAddRuleWithCallbackFail()
|
||||||
{
|
{
|
||||||
$v = new Validator(array("foo" => "baz"));
|
$v = new Validator(array("foo" => "baz"));
|
||||||
$v->rule(function ($field, $value) {
|
$v->rule(function($field, $value) {
|
||||||
return $field === "foo" && $value === "bar";
|
return $field === "foo" && $value === "bar";
|
||||||
}, "foo");
|
}, "foo");
|
||||||
|
|
||||||
@ -80,7 +81,7 @@ class ValidateAddInstanceRuleTest extends BaseTestCase
|
|||||||
public function testAddAddRuleWithCallbackFailMessage()
|
public function testAddAddRuleWithCallbackFailMessage()
|
||||||
{
|
{
|
||||||
$v = new Validator(array("foo" => "baz"));
|
$v = new Validator(array("foo" => "baz"));
|
||||||
$v->rule(function ($field, $value) {
|
$v->rule(function($field, $value) {
|
||||||
return $field === "foo" && $value === "bar";
|
return $field === "foo" && $value === "bar";
|
||||||
}, "foo", "test error message");
|
}, "foo", "test error message");
|
||||||
|
|
||||||
@ -112,8 +113,7 @@ class ValidateAddInstanceRuleTest extends BaseTestCase
|
|||||||
$this->assertEquals("foo_bar_rule", $v->getUniqueRuleName($args));
|
$this->assertEquals("foo_bar_rule", $v->getUniqueRuleName($args));
|
||||||
$this->assertEquals("foo_rule", $v->getUniqueRuleName("foo"));
|
$this->assertEquals("foo_rule", $v->getUniqueRuleName("foo"));
|
||||||
|
|
||||||
$v->addInstanceRule("foo_rule", function () {
|
$v->addInstanceRule("foo_rule", function() {});
|
||||||
});
|
|
||||||
$u = $v->getUniqueRuleName("foo");
|
$u = $v->getUniqueRuleName("foo");
|
||||||
$this->assertRegExp("/^foo_rule_[0-9]{1,5}$/", $u);
|
$this->assertRegExp("/^foo_rule_[0-9]{1,5}$/", $u);
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user