Compare commits

..

157 Commits

Author SHA1 Message Date
Willem Wollebrants
fadce39f5f
Merge pull request #365 from blueyestar/master
added missing translation for zh-cn and zh-tw
2022-10-14 13:54:24 +02:00
Willem Wollebrants
5659b0a942
Merge pull request #364 from metakin/fix-typo
typo fix
2022-10-14 13:53:54 +02:00
Willem Wollebrants
fdc64d193a
Merge pull request #359 from mehdihasanpour/add-persian
add persian language
2022-10-14 13:52:39 +02:00
Willem Wollebrants
0cbc5834b0
Merge pull request #350 from eugene-borovov/requirewith-dot-notation
Added dot notation to requireWith(out)
2022-10-14 13:52:03 +02:00
Justin Li
1b86b4f454 added missing translation for zh-cn and zh-tw 2022-10-11 11:56:38 -04:00
metakin
fbb596d220 typo fix 2022-10-11 03:22:02 +03:00
Willem Wollebrants
57a9f68f22
Merge pull request #363 from Tautve/issue_357
Fixed Issue #357
2022-10-03 09:50:30 +02:00
tautvydaskarvelis
fd902d1def Issue #357 2022-10-01 10:06:52 +03:00
mehdi hasanpour
ac960d625f add persian language 2022-07-02 15:59:33 +04:30
Willem Wollebrants
d0fb8ee84c
Merge pull request #354 from aldinhro/patch-1
Update sv.php
2022-03-16 10:16:07 +01:00
Aldin Hro
94c97e3e8e
Update sv.php
Added correct translations
2022-03-16 10:10:25 +01:00
Willem Wollebrants
9bf11f4374
Merge pull request #351 from hiroy/add-japanese-messages
Add Japanese messages for some rules
2021-12-07 09:05:12 +01:00
Hiroyuki Yamaoka
b619ef16ba Add Japanese messages for some rules 2021-12-07 14:18:08 +09:00
Eugene Borovov
b4e0d07495 Added dot notation to requireWith(out) 2021-11-21 01:55:32 +07:00
Willem Wollebrants
5ebd5d7af8
Merge pull request #344 from vlucas/issue-326
Test against PHP 8
2021-07-08 18:18:03 +02:00
Willem Wollebrants
f189549d2d make tests compatible with phpunit for php8 2021-07-07 11:55:52 +02:00
Willem Wollebrants
fe2ca630fb make tests compatible with phpunit for php8 2021-07-07 11:52:59 +02:00
Willem Wollebrants
035eca3093 make tests compatible with phpunit for php8 2021-07-07 11:47:59 +02:00
Willem Wollebrants
da91bdea70 make tests compatible with phpunit for php8 2021-07-07 11:44:08 +02:00
Willem Wollebrants
ba90097aa5
Merge pull request #343 from vlucas/issue-332
detect numeric array when keys are out of order , fixes #332
2021-07-06 14:22:56 +02:00
Willem Wollebrants
d12a77deed check first (#332) 2021-07-06 14:16:59 +02:00
Willem Wollebrants
be8cb9e074 add parameter to force in and listContains to look at array keys 2021-07-06 10:58:22 +02:00
Willem Wollebrants
500472808c detect numeric array when keys are out of order (#332) 2021-07-05 22:14:24 +02:00
Willem Wollebrants
567fbb9965
Merge pull request #340 from euantorano/patch-1
Update build status badge
2021-07-05 18:42:08 +02:00
Willem Wollebrants
ae5a778541
Merge pull request #342 from vlucas/issue-328
Correct label for 'length' in zh-cn (#328)
2021-07-05 18:41:34 +02:00
Willem Wollebrants
1c0674c23f Correct label for 'length' in zh-cn (#328) 2021-07-05 18:40:18 +02:00
Willem Wollebrants
4c7d0070dd
Merge pull request #341 from vlucas/issue-335
add missing assertion to testNotInInvalidAltSyntax (#335)
2021-07-05 18:34:54 +02:00
Willem Wollebrants
33148fa4ed add missing assertion to testNotInInvalidAltSyntax (#335) 2021-07-05 18:33:50 +02:00
Euan Torano
f0c48c4adf
Update build status badge
As GitHub Actions now runs CI, the build status badge must be from GitHub Actions.
2021-07-05 17:29:12 +01:00
Willem Wollebrants
0282ca420b
Merge pull request #338 from euantorano/feature/github-actions
Fixed #337 - add GitHub Actions workflow to run tests
2021-07-05 18:25:56 +02:00
Euan Torano
5deb47049a Added GitHub workflow file, removed Travis CI file. Changed how email DNS validation works to only check MX record. 2021-06-17 13:01:49 +01:00
Vance Lucas
f7e662e3c0
Merge pull request #334 from joebordes/sonarqube
merge IF statement with enclosing one (sonarqube static analysis)
2021-05-12 14:47:47 -05:00
joebordes
6b3c5ae608 merge IF statement with enclosing one (sonarqube static analysis) 2021-05-12 21:21:46 +02:00
Willem Wollebrants
81515dcc95
Merge pull request #325 from TomOudeRengerink/disable-auto-prepend-field-label
Allow disabling of auto prepending the field labels.
2020-12-01 12:14:45 +01:00
Tom Oude Rengerink
9f29a1b99a Added test for prepending field labels 2020-10-26 12:45:34 +01:00
Tom Oude Rengerink
bfa24585de Changed method name for readability and writting some docs. 2020-10-23 16:29:08 +02:00
Tom Oude Rengerink
6a6810e25c Removed some PHP Doc blocks generated by IDEA 2020-10-23 16:16:25 +02:00
Tom Oude Rengerink
128097ea16 Allow disabling of auto prepending the field labels shown in the error message. 2020-10-23 16:11:20 +02:00
Willem Wollebrants
9268adeeb4
Merge pull request #316 from euantorano/patch-1
Fix invalid opening bracket for arrayHasKeys example
2020-07-10 10:55:05 +02:00
Euan
a204228146
Fix mismatched open array for arrayHasKeys. 2020-07-07 16:08:30 +01:00
Willem Wollebrants
4af076d19f
Merge pull request #312 from PowerPan/sl
Add SL
2020-05-14 16:50:07 +02:00
Johannes Rudolph
3d2b0ef5f7 Add SL 2020-05-04 13:34:58 +02:00
Willem Wollebrants
43e9393009
Merge pull request #310 from sergiy-petrov/patch-1
test agains php 7.4
2020-03-05 20:31:19 +01:00
sergiy-petrov
7747441139
test agains php 7.4 2020-03-05 15:30:36 +02:00
Willem Wollebrants
87f830e554
Merge pull request #306 from vlucas/optionals
make selection of which rules to run more clear
2020-02-14 15:19:19 +01:00
Willem Wollebrants
cb2787cfcc make selection of which rules to run more clear 2020-02-14 15:08:39 +01:00
Willem Wollebrants
2baace22d8 correct documentation for integer strict mode, see #302 2020-02-14 09:44:44 +01:00
Vance Lucas
d0134c33d2
Merge pull request #293 from aecy/master
update: more french added
2019-10-24 09:46:33 -05:00
aecyM^
b7c5c09912
update: more french added 2019-09-07 15:12:40 +02:00
Vance Lucas
849d7e7dfb
Add Tidelife support message 2019-08-29 16:21:26 -05:00
Vance Lucas
47af606520
Add Security notice 2019-08-29 16:18:29 -05:00
Willem Wollebrants
a03072bed1
Merge pull request #267 from mangopeaches/required-conditionals
Adding requiredWith and requiredWithout conditional rules
2019-08-29 21:49:43 +02:00
Willem Wollebrants
76e44188e2
Merge pull request #284 from tobiashinz/listContains
List contains
2019-08-21 12:16:21 +02:00
Willem Wollebrants
89117a92f6
Update .travis.yml 2019-08-15 16:56:21 +02:00
Willem Wollebrants
ec7a20dd50
Update .travis.yml 2019-08-15 16:47:07 +02:00
Willem Wollebrants
f87d5b1905
Merge branch 'master' into listContains 2019-08-15 16:37:50 +02:00
Willem Wollebrants
4cf18608ef
Merge pull request #288 from deveplon/add-allow-null-value-in-subset-method
Add some validation to prevent PHP Warning when value in subset is null
2019-08-15 16:36:07 +02:00
Willem Wollebrants
3acb8e23b2
Merge pull request #290 from WillRy/update-es
Adding Missing Fields for Spanish language
2019-08-15 16:33:43 +02:00
William R
3f88e776f8 Adding Missing Fields
-Added translation to missing fields
-New indentation, due to the size of the string 'containsUnique'
2019-07-03 03:55:24 -03:00
Vance Lucas
d3a0a7af11
Merge pull request #289 from WillRy/update-pt-br
Adding Missing Fields
2019-07-01 14:13:46 -05:00
William R
01f09244a7 Adding Missing Fields
-Added translation to missing fields
-New indentation, due to the size of the string 'containsUnique'
2019-06-29 19:56:17 -03:00
Diego Londono
21e9dc1263 Add some validation to prevent PHP Warning when value in subset validation is null 2019-06-27 12:01:05 -03:00
Vance Lucas
a8346868c2
Create FUNDING.yml 2019-06-26 13:13:48 -05:00
Tobias Hinz
c4ea1db371 Usage documentation adjusted 2019-05-09 16:38:39 +02:00
Tobias Hinz
0976fa3a79 Added listContains 2019-05-09 16:34:50 +02:00
Willem Wollebrants
c3b4dac858
Merge pull request #282 from vlucas/iss281
use correct typehint for callable, fix #281
2019-03-21 21:12:22 +01:00
Willem Wollebrants
7705cbc5a0
Merge pull request #280 from apapsch/master
Create arrayHasKeys validator.
2019-03-21 21:02:08 +01:00
Willem Wollebrants
dfde682d93 use correct typehint for callable 2019-03-21 21:00:30 +01:00
Aljosha Papsch
2dc2f29f7f Create arrayHasKeys validator. 2019-03-11 11:46:13 +01:00
Willem Wollebrants
c6893fc67e
Merge pull request #272 from vlucas/norwegian
move existing Norwegian (Nynorsk) to seperate file
2018-12-14 22:15:14 +01:00
Willem Wollebrants
a3eba42895 move existing Norwegian (Nynorsk) to seperate file, load this by default in no.php 2018-12-14 22:07:58 +01:00
Willem Wollebrants
3f89980dcb
Merge pull request #270 from taraldr/master
New translation Norwegian Bokmål
2018-12-14 21:49:34 +01:00
Tarald Riise
6c12b1a4c1 New translation Norwegian Bokmål 2018-12-05 14:22:54 +01:00
Willem Wollebrants
dc3314a0eb
Merge pull request #268 from dgvirtual/patch-1
Update lt.php - adding missing localized strings
2018-11-19 22:37:23 +01:00
Donatas Glodenis
6e32c1455d
Update lt.php - adding missing strings 2018-11-02 23:33:53 +02:00
Tom Breese
6f125ff666 removing gitignore for netbeans project 2018-10-15 22:42:49 -04:00
Tom Breese
ee4abd9a5f required-conditionals; fixing count to isset 2018-10-15 22:41:14 -04:00
Tom Breese
757b07f3cd required-conditionals; adding strict for requiredWithAll and requiredWithoutAll 2018-10-15 22:32:48 -04:00
Tom Breese
e3c6331380 required-conditionals; fixing field typo in readme 2018-10-14 15:32:30 -04:00
Tom Breese
c8c428b3cd required-conditionals; fixing missing semi colon in readme 2018-10-14 15:30:13 -04:00
Tom Breese
17c2f05168 required-conditionals; adding requiredwith and requiredWithout for conditional requirements 2018-10-14 15:27:37 -04:00
Willem Wollebrants
661365f317
Merge pull request #266 from mangopeaches/usage-docs
Updating readme to include examples for every type
2018-10-14 14:01:40 +02:00
Tom Breese
3f19217487 update-docs; fixing regex after mass replacing php 5.4 array with php 5.3 array 2018-10-13 13:28:03 -04:00
Tom Breese
4b60befc61 usage-docs; updating arrays to php 5.3 compatible syntax 2018-10-13 13:24:43 -04:00
Tom Breese
ac5148995e usage-docs; adding dot notation usage 2018-10-13 13:06:00 -04:00
Tom Breese
ad4ab08443 usage-docs; adding dot notation usage 2018-10-13 13:04:12 -04:00
Tom Breese
d3171b8872 Adding examples for regular and alternate syntax to docs 2018-10-13 12:57:50 -04:00
Willem Wollebrants
e3b3eb31a2
Merge pull request #222 from misantron/validators-patch
Array subset and uniqueElements validators
2018-09-23 21:46:36 +02:00
misantron
ee2ed6c3b9 Change validation rule to 'subset', document and translation fixes 2018-09-23 00:53:19 +03:00
misantron
873c996db0 Fix .gitignore: remove duplicated row 2018-09-22 17:52:25 +03:00
misantron
c52612f86c Tests code style fixes 2018-09-22 17:00:34 +03:00
misantron
f70e27af56 Merge remote master branch 2018-09-22 16:35:15 +03:00
Vance Lucas
14702f00d3
Merge pull request #261 from rauwebieten/master
ipv4, ipv6 and ascii rules
2018-09-11 11:59:23 -05:00
Willem Wollebrants
b6e9079d16
Merge pull request #263 from vlucas/iss262
Filter out non-required array parts.
2018-08-24 09:27:16 +02:00
Willem Wollebrants
aaf543517d filter out non-required array parts. Fixes #262 2018-08-22 12:54:14 +02:00
Willem Wollebrants
c5a1664dab ignore PhpStorm project settings 2018-08-22 12:53:17 +02:00
peterkinamo
46ccdf1ace ascii, ipv4 and ipv6 rules added to README.md 2018-08-03 13:38:39 +02:00
peterkinamo
e5ae2c9a5f ipv4 and ipv6 rule and tests added 2018-08-03 13:02:21 +02:00
peterkinamo
971da213a3 Ascii rule added
Ascii unit test added
2018-08-03 12:28:23 +02:00
Willem Wollebrants
3511ad84af
Merge pull request #256 from vlucas/iss255
Better PHPDoc:
fix incorrect phpdoc for callable
add phpdoc for callable where needed
2018-06-27 09:23:19 +02:00
Willem Wollebrants
fcaa1d5d52 make phpdoc more specific for parameter in Validator::addInstanceRule and Validator::addRule, both need a callable 2018-06-25 22:18:19 +02:00
Willem Wollebrants
3908f086e0 fix incorrect phpdoc for callable 2018-06-25 22:15:31 +02:00
Willem Wollebrants
3c5463315b
Merge pull request #246 from peter279k/test_enhancement
Test enhancement
2018-05-06 12:45:26 +02:00
misantron
c4be38862b Validation fixes 2018-04-20 21:00:34 +03:00
peter279k
9ec218f031 Fix count() countable error message in php7.2 2018-04-14 16:56:19 +08:00
peter279k
7c1175134d Fix include setting space 2018-04-14 16:48:59 +08:00
peter279k
631c8feb36 Use composer test in Travis build script 2018-04-14 16:44:21 +08:00
peter279k
7e735e17ea Test enhancement 2018-04-14 16:37:51 +08:00
Willem Wollebrants
4c9ea18a65
Merge pull request #244 from hided62/add-korean
Adds Korean translation
2018-04-09 09:33:49 +02:00
hide_d
802c4406b3 Fix grammatical mistakes 2018-03-30 22:39:45 +09:00
hide_d
b54a25f7a9 Added Korean 2018-03-30 22:33:10 +09:00
Willem Wollebrants
b6589e85ea
Strict integer rule
Fixed strict integer rule and added more integer unit tests
2018-03-29 20:57:51 +02:00
Willem Wollebrants
c56bf573f2
Merge pull request #241 from realjay007/stop-on-first-fail
Added option to stop validation when a rule is failed
2018-03-08 16:48:01 +01:00
misantron
48dcdc7248 Merge remote-tracking branch 'remotes/upstream/master' into validators-patch 2018-03-05 22:21:09 +03:00
Julius Ijie
4103c8bd40 Forced stopOnFirstFail parameter to bool 2018-02-23 15:59:30 +01:00
Julius Ijie
8636fed8f5 Removed boolean type declaration only available on PHP7 2018-02-23 15:55:45 +01:00
Julius Ijie
6837c9dfab Added option to stop validation when a rule is failed 2018-02-23 15:25:35 +01:00
Vance Lucas
4b32e6067a
Update composer license SPDX 2018-02-10 16:02:11 -06:00
Willem Wollebrants
013672dfce
Merge pull request #231 from piotr-cz/patch-1
Fix typo in docblock
2018-02-10 14:08:48 +01:00
Willem Wollebrants
59f04de714
Merge pull request #238 from thinkjson/master
Documentation: numeric array validation example
2018-02-10 14:08:25 +01:00
Willem Wollebrants
241c456e37
Merge pull request #239 from dgvirtual/master
Translation to Lithuanian
2018-02-10 14:07:24 +01:00
Willem Wollebrants
8abb9b7220
Merge pull request #237 from mangopeaches/nested-equals-different
added nested array support for validateEquals and validateDifferent
2018-02-07 17:35:13 +01:00
Donatas Glodenis
fb8f89a519
Translation to Lithuanian 2018-02-07 15:33:59 +00:00
Tom Breese
19a1e123bd updating tests for 5.3 compatible arrays 2018-02-06 23:10:20 -05:00
Tom Breese
32dec57f69 adding nested different both unser required test 2018-02-06 23:05:25 -05:00
Tom Breese
06d1740c32 adding tests for nulls/not set values for nested and not nested equals and different methods 2018-02-06 23:02:03 -05:00
Willem Wollebrants
ef412d1160
Merge pull request #232 from jabarihunt/improved-email-validator
Add emailDNS validator
2018-02-06 08:34:20 +01:00
Mark Cahill
fd1b55ad21 Fulfilling documentation request for numeric array validation 2018-02-05 07:15:00 -05:00
Tom Breese
7c94b2ae5a added support for nested arrays in validateEquals and validateDifferent validation methods 2018-02-04 13:24:47 -05:00
Jabari Hunt
11dc3a7850
Merge pull request #1 from willemwollebrants/improved-email-validator
Improved email validator
2018-01-31 10:30:06 -06:00
Willem Wollebrants
f8e69683af add emailDNS validator to documentation 2018-01-31 16:20:58 +01:00
Willem Wollebrants
7dcc8a5089 add test for new emailDNS validator 2018-01-31 16:19:05 +01:00
Jabari
8603b2bec3 Added idn_to_ascii() with a check to make sure the function itself exists as well as a check for a required constant that it needs to function. 2018-01-05 22:28:47 -06:00
Jabari Hunt
28ef275cde Restored the original validateEmail() method. Created a new method called validateEmailDNS() that validates both the email address itself (using the ValidateEmail() method) as well as the domain name in the email address. 2018-01-01 15:11:21 -06:00
Jabari Hunt
a49bad3ed8 Merge remote-tracking branch 'origin' into improved-email-validator 2018-01-01 14:10:49 -06:00
Willem Wollebrants
1712b04f16
Merge pull request #235 from pelmered/master
Added Swedish translation file
2017-12-20 09:03:40 +01:00
Willem Wollebrants
7804f85ea8
Merge pull request #233 from shitoudev/patch-1
Update zh-cn.php
2017-12-20 09:03:06 +01:00
Peter elmered
ac79ecd1de Added Swedish translation 2017-12-19 18:36:40 +01:00
zhenwen
c0bf6b75d8
Update zh-cn.php 2017-12-14 11:17:43 +08:00
Jabari Hunt
55154359dc Fixed a typo that was introduces in an unrelated comment. 2017-12-13 16:06:31 -06:00
Jabari Hunt
255384baa8 Made the domain check an option (via third method param). 2017-12-13 14:52:24 -06:00
Jabari Hunt
ae7716c900 Improved the email validator by making sure the domain name is valid. 2017-12-13 12:30:45 -06:00
Piotr
2438da6a99
Fix typo in docblock 2017-12-08 16:00:16 +01:00
Willem Wollebrants
42637ed954
Merge pull request #230 from vlucas/fixTest
Make testRequiredAllowEmpty() test 2 different usages
2017-12-02 21:56:17 +01:00
Willem Wollebrants
d1563d520f Make sure testRequiredAllowEmpty() tests 2 different usages for required rule 2017-12-02 21:28:13 +01:00
Vance Lucas
290113fac0
Merge pull request #225 from gabriel-caruso/phpunit
Use PHPUnit\Framework\TestCase instead of PHPUnit_Framework_TestCase
2017-11-15 10:35:54 -06:00
Gabriel Caruso
14a467ba24 Use PHPUnit\Framework\TestCase instead of PHPUnit_Framework_TestCase 2017-11-11 02:28:10 -02:00
misantron
36404a83b7 Merge branch 'master' into validators-patch 2017-11-01 23:43:09 +03:00
Willem Wollebrants
87775d7626
Merge pull request #224 from vlucas/issue223
remove unused parameter for required rule
2017-10-31 00:15:06 +01:00
Willem Wollebrants
890cf6a104 let's see if we can keep 5.3 still 2017-10-30 20:02:29 +01:00
Willem Wollebrants
3da6518e38 time to no longer test for php 5.3 2017-10-30 19:49:58 +01:00
Willem Wollebrants
9726d0f835 remove unused parameter for required rule 2017-10-30 19:44:17 +01:00
misantron
b0ddfb3a37 Merge remote-tracking branch 'origin/validators-patch' into validators-patch
# Conflicts:
#	src/Valitron/Validator.php
2017-10-26 23:11:06 +03:00
misantron
d9a466b833 Array contains and unique validators added, code style fixes 2017-10-26 23:09:45 +03:00
Dennis Meckel
eb436a382f Fixed strict integer rule and added more integer unit tests 2017-10-13 19:39:59 +02:00
misantron
ccc6df8ba0 Merge branch 'master' into validators-patch
Conflicts:
	src/Valitron/Validator.php
2016-12-26 16:31:14 +03:00
misantron
11139b8534 Code style changes and fixes 2016-12-26 16:28:59 +03:00
50 changed files with 4013 additions and 624 deletions

1
.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1 @@
tidelift: "packagist/vlucas/valitron"

73
.github/workflows/test.yml vendored Normal file
View File

@ -0,0 +1,73 @@
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
View File

@ -2,3 +2,5 @@
composer.phar
composer.lock
vendor
.idea/
.phpunit.result.cache

View File

@ -1,20 +0,0 @@
# 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.3
- 5.4
- 5.5
- 5.6
- hhvm
matrix:
allow_failures:
- php: hhvm
before_script:
- composer install
# Script to run tests
script: ./vendor/bin/phpunit

978
README.md

File diff suppressed because it is too large Load Diff

View File

@ -3,24 +3,32 @@
"type": "library",
"description": "Simple, elegant, stand-alone validation library with NO dependencies",
"keywords": ["validation", "validator", "valid"],
"homepage": "http://github.com/vlucas/valitron",
"license" : "BSD",
"homepage": "https://github.com/vlucas/valitron",
"license": "BSD-3-Clause",
"authors": [
{
"name": "Vance Lucas",
"email": "vance@vancelucas.com",
"homepage": "http://www.vancelucas.com"
"homepage": "https://www.vancelucas.com"
}
],
"require": {
"php": ">=5.3.2"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
"phpunit/phpunit": ">=4.8.35"
},
"suggest": {
"ext-mbstring": "It can support the multiple bytes string length."
},
"autoload": {
"psr-0": {
"Valitron": "src/"
"psr-4": {
"Valitron\\": "src/Valitron"
}
},
"autoload-dev": {
"psr-4": {
"Valitron\\": "tests/Valitron"
}
},
"scripts": {

View File

@ -11,6 +11,7 @@ return array(
'min' => "يجب ان يكون اعلي من %s",
'max' => "يجب ان يكون اقل من %s",
'in' => "الُمدخل يغير صحيح",
'listContains' => "الُمدخل يغير صحيح",
'notIn' => "الُمدخل يغير صحيح",
'ip' => "رقم الإتصال غير صحيح",
'email' => "البريد الألكتروني غير صحيح",

View File

@ -10,6 +10,7 @@ return array(
'length' => "%d qədər uzunluğu olmalıdır",
'min' => "minimum %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",
'notIn' => "yalnış dəyər ehtiva edir",
'ip' => "düzgün IP ünvanı deyil",

View File

@ -10,6 +10,7 @@ return array(
'length' => "трябва да бъде %d символа дълго",
'min' => "трябвя да бъде поне %s",
'max' => "трябва да бъде не повече от %s",
'listContains' => "съдържа невалидна стойност",
'in' => "съдържа невалидна стойност",
'notIn' => "съдържа невалидна стойност",
'ip' => "е невалиден IP адрес",

View File

@ -10,6 +10,7 @@ return array(
'length' => "kann nicht länger als %d sein",
'min' => "muss größer als %s sein",
'max' => "muss kleiner als %s sein",
'listContains' => "enthält einen ungültigen Wert",
'in' => "enthält einen ungültigen Wert",
'notIn' => "enthält einen ungültigen Wert",
'ip' => "enthält keine gültige IP-Addresse",

View File

@ -10,6 +10,7 @@ return array(
'length' => "πρέπει να είναι μεγαλύτερο από %d",
'min' => "πρέπει να είναι τουλάχιστον %s",
'max' => "δεν πρέπει να είναι περισσότερο από %s",
'listContains' => "περιέχει μη έγκυρη τιμή",
'in' => "περιέχει μη έγκυρη τιμή",
'notIn' => "περιέχει μη έγκυρη τιμή",
'ip' => "δεν είναι έγκυρη διεύθυνση IP",

View File

@ -10,9 +10,12 @@ return array(
'length' => "must be %d characters long",
'min' => "must be at least %s",
'max' => "must be no more than %s",
'listContains' => "contains invalid value",
'in' => "contains invalid value",
'notIn' => "contains invalid value",
'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",
'url' => "is not a valid URL",
'urlActive' => "must be an active domain",
@ -30,5 +33,10 @@ return array(
'creditCard' => "must be a valid credit card number",
'lengthMin' => "must be at least %d characters long",
'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",
);

View File

@ -30,5 +30,8 @@ return array(
'creditCard' => "debe ser un numero de tarjeta de crédito válido",
"lengthMin" => "debe tener al menos %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 Normal file
View File

@ -0,0 +1,42 @@
<?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' => "همه کلیدهای الزامی را ندارد",
);

View File

@ -10,6 +10,7 @@ return array(
'length' => "on lyhyempi kuin %d",
'min' => "ei ole vähintään %s",
'max' => "ei ole enintään %s",
'listContains' => "sisältää virheellisen arvon",
'in' => "sisältää virheellisen arvon",
'notIn' => "sisältää virheellisen arvon",
'ip' => "ei ole oikeanmuotoinen IP-osoite",

View File

@ -10,6 +10,7 @@ return array(
'length' => "doit être plus long que %d",
'min' => "doit être plus grand que %s",
'max' => "doit être plus petit que %s",
'listContains' => "contient une valeur non valide",
'in' => "contient une valeur non valide",
'notIn' => "contient une valeur non valide",
'ip' => "n'est pas une adresse IP valide",
@ -30,5 +31,10 @@ return array(
'creditCard' => "doit être un numéro de carte de crédit valide",
'lengthMin' => "doit avoir au moins %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"
);

View File

@ -10,6 +10,7 @@ return array(
'length' => "harus lebih panjang dari %d",
'min' => "harus lebih besar dari %s",
'max' => "harus kurang dari %s",
'listContains' => "berisi nilai/value yang tidak valid",
'in' => "berisi nilai/value yang tidak valid",
'notIn' => "berisi nilai/value yang tidak valid",
'ip' => "format alamat IP tidak benar",

View File

@ -10,6 +10,7 @@ return array(
'length' => "deve avere una lunghezza di %d",
'min' => "deve essere superiore a %s",
'max' => "deve essere inferiore a %s",
'listContains' => "contiene un valore non valido",
'in' => "contiene un valore non valido",
'notIn' => "contiene un valore non valido",
'ip' => "non è un indirizzo IP valido",

View File

@ -10,9 +10,12 @@ return array(
'length' => "は%d文字で入力してください",
'min' => "には%sより大きな値を入力してください",
'max' => "には%sより小さな値を入力してください",
'listContains' => "には選択できない値が含まれています",
'in' => "には選択できない値が含まれています",
'notIn' => "には選択できない値が含まれています",
'ip' => "はIPアドレスの書式として正しくありません",
'ipv4' => "はIPv4のIPアドレスの書式として正しくありません",
'ipv6' => "はIPv6のIPアドレスの書式として正しくありません",
'email' => "はメールアドレスの書式として正しくありません",
'url' => "はURLの書式として正しくありません",
'urlActive' => "はアクティブなドメインではありません",
@ -31,4 +34,9 @@ return array(
'lengthMin' => "は%d文字以上入力してください",
'lengthMax' => "は%d文字以内で入力してください",
'instanceOf' => "は「%s」のインスタンスではありません",
'containsUnique' => "は重複のないように入力してください",
'requiredWith' => "を入力してください",
'requiredWithout' => "を入力してください",
'subset' => "には選択できない値が含まれています",
'arrayHasKeys' => "の必要な項目が選択されていません",
);

35
lang/ko.php Normal file
View File

@ -0,0 +1,35 @@
<?php
return array(
'required' => "을(를) 입력해야 합니다.",
'equals' => "은(는) '%s'와(과) 같아야 합니다.",
'different' => "은(는) '%s'와(과) 달라야 합니다.",
'accepted' => "을(를) 동의해야 합니다.",
'numeric' => "은(는) 숫자여야 합니다.",
'integer' => "은(는) 정수여야 합니다.",
'length' => "의 길이는 %d 이어야 합니다.",
'min' => "은(는) %s 이상이어야 합니다.",
'max' => "은(는) %s 이하여야 합니다.",
'listContains' => "은(는) 올바르지 않은 값을 포함하고 있습니다.",
'in' => "은(는) 올바르지 않은 값을 포함하고 있습니다.",
'notIn' => "은(는) 올바르지 않은 값을 포함하고 있습니다.",
'ip' => "은(는) 올바르지 않은 IP입니다.",
'email' => "은(는) 올바르지 않은 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' => "은(는) boolean이어야 합니다.",
'lengthBetween' => "의 길이는 %d에서 %d 사이여야 합니다.",
'creditCard' => "은(는) 올바른 신용카드 번호가 아닙니다.",
'lengthMin' => "의 길이는 %d 이상이어야 합니다.",
'lengthMax' => "의 길이는 %d을(를) 넘을 수 없습니다.",
'instanceOf' => "는 '%s'의 객체여야 합니다."
);

38
lang/lt.php Normal file
View File

@ -0,0 +1,38 @@
<?php
return array(
'required' => "yra privalomas",
'equals' => "reikšmė turi būti tokia pati, kaip „%s“",
'different' => "turi būti kitokia, nei „%s“",
'accepted' => "turi būti priimta",
'numeric' => "turi būti sveikasis skaičius",
'integer' => "turi būti skaičius",
'length' => "turi būti %d ženklų ilgio",
'min' => "turi būti bent %s",
'max' => "turi būti ne daugiau kaip %s",
'listContains' => "turi neteisingą vertę",
'in' => "turi neteisingą vertę",
'notIn' => "turi neteisingą vertę",
'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",
'url' => "nėra teisingas URL",
'urlActive' => "turi būti aktyvus domenas",
'alpha' => "turi turėti tik raides a-ž",
'alphaNum' => "turi turėti tik raides a-ž ir/ar skaičius 0-9",
'slug' => "turi turėti tik raides a-ž, skaičius 0-9, brukšnelius ir apatinius brukšnelius",
'regex' => "yra neteisingų ženklų",
'date' => "nėra teisinga data",
'dateFormat' => "turi būti „%s“ formato data",
'dateBefore' => "turi būti data, ankstesnė nei „%s“",
'dateAfter' => "turi būti data, vėlesnė nei „%s“",
'contains' => "turi turėti %s",
'boolean' => "turi būti būlio (taip/ne) tipo",
'lengthBetween' => "turi būti nuo %d iki %d ilgio",
'creditCard' => "turi būti teisingas kreditinės kortelės numeris",
'lengthMin' => "turi būti bent %d ženklų ilgio",
'lengthMax' => "turi būti ne ilgesnis nei %d ženklų",
'instanceOf' => "turi būti „%s“ atvejis",
'containsUnique' => "turi turėti tik unikalius elementus",
'subset' => "turi elementą, kurio nėra sąraše"
);

View File

@ -10,6 +10,7 @@ return array(
'length' => "nedrīkst būt garāks par %d simboliem",
'min' => "jābūt garā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",
'notIn' => "lauks satur nederīgu vērtību",
'ip' => " lauks nav derīga IP adrese",

39
lang/nb.php Normal file
View File

@ -0,0 +1,39 @@
<?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"
);

View File

@ -10,6 +10,7 @@ return array(
'length' => "moet minstens %d karakters lang zijn",
'min' => "moet minstens %s zijn",
'max' => "mag niet meer zijn dan %s",
'listContains' => "bevat een ongeldige waarde",
'in' => "bevat een ongeldige waarde",
'notIn' => "bevat een ongeldige waarde",
'ip' => "is geen geldig IP-adres",

35
lang/nn.php Normal file
View File

@ -0,0 +1,35 @@
<?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'"
);

View File

@ -1,34 +1,3 @@
<?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'"
);
return include __DIR__ . '/nn.php';

View File

@ -10,6 +10,7 @@ return array(
'length' => "musi być dłuższe niż %d",
'min' => "musi być przynajmniej %s",
'max' => "nie może być większe niż %s",
'listContains' => "zawiera nieprawidłową wartość",
'in' => "zawiera nieprawidłową wartość",
'notIn' => "zawiera nieprawidłową wartość",
'ip' => "nie jest prawidłowym adresem IP",

View File

@ -30,5 +30,8 @@ return array(
'creditCard' => "deve ser um numero de cartão de credito válido",
'lengthMin' => "deve ter ao menos %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"
);

View File

@ -10,6 +10,7 @@ return array(
'length' => "trebuie sa fie mai lung decat %d",
'min' => "trebuie sa fie cel putin %s",
'max' => "nu trebuie sa fie mai mult de %s",
'listContains' => "contine caractere invalide",
'in' => "contine caractere invalide",
'notIn' => "contine o valoare invalida",
'ip' => "nu este o adresa IP valida",

View File

@ -2,17 +2,20 @@
return array(
'required' => "обязательно для заполнения",
'equals' => "должно содержать '%s'",
'equals' => "должно совпадать со значением '%s'",
'different' => "должно отличаться от '%s'",
'accepted' => "должно быть указано",
'numeric' => "должно содержать числовое значение",
'integer' => "должно быть числом",
'length' => "должно быть длиннее, чем %d",
'min' => "должно быть больше, чем %s",
'max' => "должно быть меньше, чем %s",
'min' => "должно быть не менее, чем %s",
'max' => "должно быть не более, чем %s",
'listContains' => "содержит неверное значение",
'in' => "содержит неверное значение",
'notIn' => "содержит неверное значение",
'ip' => "не является валидным IP адресом",
'ipv4' => "не является валидным IPv4 адресом",
'ipv6' => "не является валидным IPv6 адресом",
'email' => "не является валидным email адресом",
'url' => "не является валидной ссылкой",
'urlActive' => "содержит не активную ссылку",
@ -30,5 +33,7 @@ return array(
'creditCard' => "должно быть номером кредитной карты",
'lengthMin' => "должно содержать более %d символов",
'lengthMax' => "должно содержать менее %d символов",
'instanceOf' => "должно быть объектом класса '%s'"
'instanceOf' => "должно быть объектом класса '%s'",
'containsUnique' => "должно содержать только уникальные элементы",
'subset' => "содержит элемент, не указанный в списке",
);

View File

@ -10,6 +10,7 @@ return array(
'length' => "musí byť dlhý aspoň %d",
'min' => "musí byť dlhý minimálne %s",
'max' => "musí byť maximálne %s",
'listContains' => "obsahuje nepovolenú hodnotu",
'in' => "obsahuje nepovolenú hodnotu",
'notIn' => "obsahuje nepovolenú hodnotu",
'ip' => "nie je korektná IP adresa",

42
lang/sl.php Normal file
View File

@ -0,0 +1,42 @@
<?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",
);

35
lang/sv.php Normal file
View File

@ -0,0 +1,35 @@
<?php
return array(
'required' => "är obligatorisk",
'equals' => "måste vara samma som '%s'",
'different' => "får inte vara samma som '%s'",
'accepted' => "måste accepteras",
'numeric' => "måste vara numerisk",
'integer' => "måste vara ett heltal",
'length' => "måste vara %d tecken långt",
'min' => "måste vara minst %s",
'max' => "får inte vara mer än %s",
'listContains' => "innehåller ogiltigt värde",
'in' => "innehåller ogiltigt värde",
'notIn' => "innehåller ogiltigt värde",
'ip' => "är inte en giltig IP-adress",
'email' => "är inte en giltig e-postadress",
'url' => "är inte en giltig URL",
'urlActive' => "måste vara ett aktivt domännamn",
'alpha' => "får bara innehålla bokstäver a-z",
'alphaNum' => "får bara innehå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",
'regex' => "innehåller ogiltiga tecken",
'date' => "är inte ett giltigt datum",
'dateFormat' => "måste vara ett datum med formatet '%s'",
'dateBefore' => "måste vara ett datum före '%s'",
'dateAfter' => "måste vara ett datum efter '%s'",
'contains' => "måste innehålla %s",
'boolean' => "måste vara ett booleskt värde",
'lengthBetween' => "måste vara mellan %d och %d tecken långt",
'creditCard' => "måste vara ett giltigt kreditkortsnummer",
'lengthMin' => "måste vara minst %d tecken långt",
'lengthMax' => "får inte överstiga %d tecken",
'instanceOf' => "måste vara en instans av '%s'"
);

View File

@ -10,6 +10,7 @@ return array(
'length' => "ต้องมีความยาวมากกว่า %d",
'min' => "ต้องมีอย่างน้อย %s",
'max' => "ต้องไม่มากเกิน %s",
'listContains' => "ประกอบด้วยค่าที่ไม่ถูกต้อง",
'in' => "ประกอบด้วยค่าที่ไม่ถูกต้อง",
'notIn' => "ประกอบด้วยค่าที่ไม่ถูกต้อง",
'ip' => "ไม่ใช่ IP ที่ถูกต้อง",

View File

@ -10,6 +10,7 @@ return array(
'length' => "en az %d adet uzunluğunda olmalı",
'min' => "en az böyle olmalı %s",
'max' => "bundan daha fazla olmalı %s",
'listContains' => "geçersiz değer içeriyor",
'in' => "geçersiz değer içeriyor",
'notIn' => "geçersiz değer içeriyor",
'ip' => "geçerli bir IP adresi değil",
@ -28,7 +29,7 @@ return array(
'boolean' => "boolean olmalı",
'lengthBetween' => "%d ve %d karakter arasında olmalı",
'creditCard' => "geçerli bir kredi kartı numarası olmalı",
"lengthMin" => "%d katakterden fazla içermeli",
"lengthMin" => "%d karakterden fazla içermeli",
"lengthMax" => "%d karakterden az içermeli",
"instanceOf" => "bunun bir örneği olmalı '%s'"
);

View File

@ -10,6 +10,7 @@ return array(
'length' => "має бути довшим, ніж %d",
'min' => "має бути більше, ніж %s",
'max' => "повинно бути менше, ніж %s",
'listContains' => "містить невірне значення",
'in' => "містить невірне значення",
'notIn' => "містить невірне значення",
'ip' => "не є валідною IP адресою",

View File

@ -10,6 +10,7 @@ return array(
'length' => "phải dài hơn %d",
'min' => "ít nhất %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ệ",
'notIn' => "chứa giá trị không hợp lệ",
'ip' => "địa chỉ IP không hợp lệ",

View File

@ -7,9 +7,10 @@ return array(
'accepted' => "必须接受",
'numeric' => "只能是数字",
'integer' => "只能是整数",
'length' => "长度必须于 %d",
'length' => "长度必须于 %d",
'min' => "必须大于 %s",
'max' => "必须小于 %s",
'listContains' => "无效的值",
'in' => "无效的值",
'notIn' => "无效的值",
'ip' => "无效IP地址",
@ -24,5 +25,16 @@ return array(
'dateFormat' => "日期的格式应该为 '%s'",
'dateBefore' => "日期必须在 '%s' 之前",
'dateAfter' => "日期必须在 '%s' 之后",
'contains' => "必须包含 %s"
'contains' => "必须包含 %s",
'boolean' => "必须是真或假",
'lengthBetween' => "长度只能介于 %d 和 %d 之间",
'creditCard' => "信用卡号码不正确",
'lengthMin' => "长度必须大于 %d",
'lengthMax' => "长度必须小于 %d",
'instanceOf' => "必须是 '%s' 的实例",
'containsUnique' => "必须仅包含唯一的元素",
'requiredWith' => "是必须的",
'requiredWithout' => "是必须的",
'subset' => "包含不在列表中的项目",
'arrayHasKeys' => "不包含所有必需的键",
);

View File

@ -10,6 +10,7 @@ return array(
'length' => "長度必須大於 %d",
'min' => "必須大於 %s",
'max' => "必須小於 %s",
'listContains' => "無效的值",
'in' => "無效的值",
'notIn' => "無效的值",
'ip' => "無效IP地址",
@ -24,5 +25,16 @@ return array(
'dateFormat' => "日期的格式應該為 '%s'",
'dateBefore' => "日期必須在 '%s' 之前",
'dateAfter' => "日期必須在 '%s' 之後",
'contains' => "必須包含 %s"
'contains' => "必須包含 %s",
'boolean' => "必須是真或假",
'lengthBetween' => "長度只能介於 %d 和 %d 之間",
'creditCard' => "信用卡號碼不正確",
'lengthMin' => "長度必須大於 %d",
'lengthMax' => "長度必須小於 %d",
'instanceOf' => "必須是 '%s' 的實例",
'containsUnique' => "必須僅包含唯一的元素",
'requiredWith' => "是必須的",
'requiredWithout' => "是必須的",
'subset' => "包含不在列表中的項目",
'arrayHasKeys' => "不包含所有必需的鍵",
);

View File

@ -7,7 +7,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
>
<testsuites>

View File

@ -1,4 +1,5 @@
<?php
namespace Valitron;
/**
@ -77,6 +78,16 @@ class Validator
*/
protected $validUrlPrefixes = array('http://', 'https://', 'ftp://');
/**
* @var bool
*/
protected $stop_on_first_fail = false;
/**
* @var bool
*/
protected $prepend_labels = true;
/**
* Setup validation
*
@ -138,6 +149,14 @@ class Validator
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
*
@ -146,16 +165,14 @@ class Validator
* @param array $params
* @return bool
*/
protected function validateRequired($field, $value, array $params= array(), array $fields = array())
protected function validateRequired($field, $value, $params = array())
{
if (isset($params[0]) && (bool)$params[0]) {
$find = $this->getPart($this->_fields, explode('.', $field), true);
return $find[1];
}
if (is_null($value)) {
return false;
} elseif (is_string($value) && trim($value) === '') {
if (is_null($value) || (is_string($value) && trim($value) === '')) {
return false;
}
@ -168,14 +185,13 @@ class Validator
* @param string $field
* @param mixed $value
* @param array $params
* @internal param array $fields
* @return bool
*/
protected function validateEquals($field, $value, array $params)
{
$field2 = $params[0];
return isset($this->_fields[$field2]) && $value == $this->_fields[$field2];
// extract the second field value, this accounts for nested array values
list($field2Value, $multiple) = $this->getPart($this->_fields, explode('.', $params[0]));
return isset($field2Value) && $value == $field2Value;
}
/**
@ -184,14 +200,13 @@ class Validator
* @param string $field
* @param mixed $value
* @param array $params
* @internal param array $fields
* @return bool
*/
protected function validateDifferent($field, $value, array $params)
{
$field2 = $params[0];
return isset($this->_fields[$field2]) && $value != $this->_fields[$field2];
// extract the second field value, this accounts for nested array values
list($field2Value, $multiple) = $this->getPart($this->_fields, explode('.', $params[0]));
return isset($field2Value) && $value != $field2Value;
}
/**
@ -246,7 +261,7 @@ class Validator
{
if (isset($params[0]) && (bool)$params[0]) {
//strict mode
return preg_match('/^-?([0-9])+$/i', $value);
return preg_match('/^([0-9]|-[1-9]|-?[1-9][0-9]*)$/i', $value);
}
return filter_var($value, \FILTER_VALIDATE_INT) !== false;
@ -258,7 +273,6 @@ class Validator
* @param string $field
* @param mixed $value
* @param array $params
* @internal param array $fields
* @return bool
*/
protected function validateLength($field, $value, $params)
@ -278,7 +292,7 @@ class Validator
* @param string $field
* @param mixed $value
* @param array $params
* @return boolean
* @return bool
*/
protected function validateLengthBetween($field, $value, $params)
{
@ -294,7 +308,7 @@ class Validator
* @param mixed $value
* @param array $params
*
* @return boolean
* @return bool
*/
protected function validateLengthMin($field, $value, $params)
{
@ -310,7 +324,7 @@ class Validator
* @param mixed $value
* @param array $params
*
* @return boolean
* @return bool
*/
protected function validateLengthMax($field, $value, $params)
{
@ -342,7 +356,6 @@ class Validator
* @param string $field
* @param mixed $value
* @param array $params
* @internal param array $fields
* @return bool
*/
protected function validateMin($field, $value, $params)
@ -362,7 +375,6 @@ class Validator
* @param string $field
* @param mixed $value
* @param array $params
* @internal param array $fields
* @return bool
*/
protected function validateMax($field, $value, $params)
@ -382,7 +394,6 @@ class Validator
* @param string $field
* @param mixed $value
* @param array $params
* @return bool
*/
protected function validateBetween($field, $value, $params)
@ -405,13 +416,16 @@ class Validator
* @param string $field
* @param mixed $value
* @param array $params
* @internal param array $fields
* @return bool
*/
protected function validateIn($field, $value, $params)
{
$isAssoc = array_values($params[0]) !== $params[0];
if ($isAssoc) {
$forceAsAssociative = false;
if (isset($params[2])) {
$forceAsAssociative = (bool) $params[2];
}
if ($forceAsAssociative || $this->isAssociativeArray($params[0])) {
$params[0] = array_keys($params[0]);
}
@ -423,13 +437,39 @@ class Validator
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
*
* @param string $field
* @param mixed $value
* @param array $params
* @internal param array $fields
* @return bool
*/
protected function validateNotIn($field, $value, $params)
@ -441,7 +481,7 @@ class Validator
* Validate a field contains a given string
*
* @param string $field
* @param mixed $value
* @param string $value
* @param array $params
* @return bool
*/
@ -459,7 +499,6 @@ class Validator
$strict = (bool)$params[1];
}
$isContains = false;
if ($strict) {
if (function_exists('mb_strpos')) {
$isContains = mb_strpos($value, $params[0]) !== false;
@ -476,6 +515,46 @@ class Validator
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
*
@ -488,6 +567,30 @@ class Validator
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
*
@ -500,6 +603,49 @@ class Validator
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
*
* @param string $field
* @param mixed $value
* @return bool
*/
protected function validateEmailDNS($field, $value)
{
if (!is_string($value)) {
return false;
}
if ($this->validateEmail($field, $value)) {
$domain = ltrim(stristr($value, '@'), '@') . '.';
if (function_exists('idn_to_ascii') && defined('INTL_IDNA_VARIANT_UTS46')) {
$domain = idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46);
}
return checkdnsrr($domain, 'MX');
}
return false;
}
/**
* Validate that a field is a valid URL by syntax
*
@ -509,6 +655,10 @@ class Validator
*/
protected function validateUrl($field, $value)
{
if (!is_string($value)) {
return false;
}
foreach ($this->validUrlPrefixes as $prefix) {
if (strpos($value, $prefix) !== false) {
return filter_var($value, \FILTER_VALIDATE_URL) !== false;
@ -527,6 +677,10 @@ class Validator
*/
protected function validateUrlActive($field, $value)
{
if (!is_string($value)) {
return false;
}
foreach ($this->validUrlPrefixes as $prefix) {
if (strpos($value, $prefix) !== false) {
$host = parse_url(strtolower($value), PHP_URL_HOST);
@ -615,7 +769,6 @@ class Validator
* @param string $field
* @param mixed $value
* @param array $params
* @internal param array $fields
* @return bool
*/
protected function validateDateFormat($field, $value, $params)
@ -631,7 +784,6 @@ class Validator
* @param string $field
* @param mixed $value
* @param array $params
* @internal param array $fields
* @return bool
*/
protected function validateDateBefore($field, $value, $params)
@ -648,7 +800,6 @@ class Validator
* @param string $field
* @param mixed $value
* @param array $params
* @internal param array $fields
* @return bool
*/
protected function validateDateAfter($field, $value, $params)
@ -758,13 +909,11 @@ class Validator
} elseif (isset($cards)) {
// if we have cards, check our users card against only the ones we have
foreach ($cards as $card) {
if (in_array($card, array_keys($cardRegex))) {
if (in_array($card, array_keys($cardRegex)) && preg_match($cardRegex[$card], $value) === 1) {
// if the card is valid, we want to stop looping
if (preg_match($cardRegex[$card], $value) === 1) {
return true;
}
}
}
} else {
// loop through every card
foreach ($cardRegex as $regex) {
@ -801,12 +950,125 @@ class Validator
return $isInstanceOf;
}
//Validate optional field
protected function validateOptional($field, $value, $params) {
/**
* 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 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
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
*
@ -836,12 +1098,12 @@ class Validator
* Add an error to error messages array
*
* @param string $field
* @param string $msg
* @param string $message
* @param array $params
*/
public function error($field, $msg, array $params = array())
public function error($field, $message, array $params = array())
{
$msg = $this->checkAndSetLabel($field, $msg, $params);
$message = $this->checkAndSetLabel($field, $message, $params);
$values = array();
// Printed values need to be in string format
@ -857,26 +1119,24 @@ class Validator
}
}
// Use custom label instead of field name if set
if (is_string($params[0])) {
if (isset($this->_labels[$param])) {
if (is_string($params[0]) && isset($this->_labels[$param])) {
$param = $this->_labels[$param];
}
}
$values[] = $param;
}
$this->_errors[$field][] = vsprintf($msg, $values);
$this->_errors[$field][] = vsprintf($message, $values);
}
/**
* Specify validation message to use for error for the last validation rule
*
* @param string $msg
* @return $this
* @param string $message
* @return Validator
*/
public function message($msg)
public function message($message)
{
$this->_validations[count($this->_validations) - 1]['message'] = $msg;
$this->_validations[count($this->_validations) - 1]['message'] = $message;
return $this;
}
@ -900,7 +1160,7 @@ class Validator
}
// Catches the case where the data isn't an array or object
if (is_scalar($data)) {
return array(NULL, false);
return array(null, false);
}
$identifier = array_shift($identifiers);
// Glob match
@ -915,48 +1175,60 @@ class Validator
}
}
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){
//when empty values are allowed, we only care if the key exists
return array(null, array_key_exists($identifier, $data));
}
return array(null, false);
}
// Match array element
} // Match array element
elseif (count($identifiers) === 0) {
if ($allow_empty) {
//when empty values are allowed, we only care if the key exists
return array(null, array_key_exists($identifier, $data));
}
return array($data[$identifier], false);
}
// We need to go deeper
return array($data[$identifier], $allow_empty);
} // We need to go deeper
else {
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
*
* @return boolean
* @return bool
*/
public function validate()
{
$set_to_break = false;
foreach ($this->_validations as $v) {
foreach ($v['fields'] as $field) {
list($values, $multiple) = $this->getPart($this->_fields, explode('.', $field));
list($values, $multiple) = $this->getPart($this->_fields, explode('.', $field), false);
// 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))
) {
if (! $this->validationMustBeExcecuted($v, $field, $values, $multiple)){
continue;
}
@ -970,6 +1242,8 @@ class Validator
if (!$multiple) {
$values = array($values);
} else if (! $this->hasRule('required', $field)){
$values = array_filter($values);
}
$result = true;
@ -979,13 +1253,29 @@ class Validator
if (!$result) {
$this->error($field, $v['message'], $v['params']);
if ($this->stop_on_first_fail) {
$set_to_break = true;
break;
}
}
}
if ($set_to_break) {
break;
}
}
return count($this->errors()) === 0;
}
/**
* Should the validation stop a rule is failed
* @param bool $stop
*/
public function stopOnFirstFail($stop = true)
{
$this->stop_on_first_fail = (bool)$stop;
}
/**
* Returns all rule callbacks, the static and instance ones.
*
@ -1011,18 +1301,15 @@ class Validator
*
* @param string $name The name of the rule
* @param string $field The name of the field
* @return boolean
* @return bool
*/
protected function hasRule($name, $field)
{
foreach ($this->_validations as $validation) {
if ($validation['rule'] == $name) {
if (in_array($field, $validation['fields'])) {
if ($validation['rule'] == $name && in_array($field, $validation['fields'])) {
return true;
}
}
}
return false;
}
@ -1030,17 +1317,18 @@ class Validator
protected static function assertRuleCallback($callback)
{
if (!is_callable($callback)) {
throw new \InvalidArgumentException('Second argument must be a valid callback. Given argument was not callable.');
throw new \InvalidArgumentException(
'Second argument must be a valid callback. Given argument was not callable.'
);
}
}
/**
* Adds a new validation rule callback that is tied to the current
* instance only.
*
* @param string $name
* @param mixed $callback
* @param callable $callback
* @param string $message
* @throws \InvalidArgumentException
*/
@ -1056,14 +1344,13 @@ class Validator
* Register new validation rule callback
*
* @param string $name
* @param mixed $callback
* @param callable $callback
* @param string $message
* @throws \InvalidArgumentException
*/
public static function addRule($name, $callback, $message = null)
{
if ($message === null)
{
if ($message === null) {
$message = static::ERROR_DEFAULT;
}
@ -1073,18 +1360,20 @@ class Validator
static::$_ruleMessages[$name] = $message;
}
/**
* @param mixed $fields
* @return string
*/
public function getUniqueRuleName($fields)
{
if (is_array($fields))
{
if (is_array($fields)) {
$fields = implode("_", $fields);
}
$orgName = "{$fields}_rule";
$name = $orgName;
$rules = $this->getRules();
while (isset($rules[$name]))
{
while (isset($rules[$name])) {
$name = $orgName . "_" . rand(0, 10000);
}
@ -1092,7 +1381,7 @@ class Validator
}
/**
* Returns true if either a valdiator with the given name has been
* Returns true if either a validator with the given name has been
* registered or there is a default validator by that name.
*
* @param string $name
@ -1108,9 +1397,9 @@ class Validator
/**
* Convenience method to add a single validation rule
*
* @param string|callback $rule
* @param string|callable $rule
* @param array|string $fields
* @return $this
* @return Validator
* @throws \InvalidArgumentException
*/
public function rule($rule, $fields)
@ -1119,11 +1408,10 @@ class Validator
$params = array_slice(func_get_args(), 2);
if (is_callable($rule)
&& !(is_string($rule) && $this->hasValidator($rule)))
{
&& !(is_string($rule) && $this->hasValidator($rule))) {
$name = $this->getUniqueRuleName($fields);
$msg = isset($params[0]) ? $params[0] : null;
$this->addInstanceRule($name, $rule, $msg);
$message = isset($params[0]) ? $params[0] : null;
$this->addInstanceRule($name, $rule, $message);
$rule = $name;
}
@ -1131,13 +1419,15 @@ class Validator
if (!isset($errors[$rule])) {
$ruleMethod = 'validate' . ucfirst($rule);
if (!method_exists($this, $ruleMethod)) {
throw new \InvalidArgumentException("Rule '" . $rule . "' has not been registered with " . __CLASS__ . "::addRule().");
throw new \InvalidArgumentException(
"Rule '" . $rule . "' has not been registered with " . get_called_class() . "::addRule()."
);
}
}
// Ensure rule has an accompanying message
$msgs = $this->getRuleMessages();
$message = isset($msgs[$rule]) ? $msgs[$rule] : self::ERROR_DEFAULT;
$messages = $this->getRuleMessages();
$message = isset($messages[$rule]) ? $messages[$rule] : self::ERROR_DEFAULT;
// Ensure message contains field label
if (function_exists('mb_strpos')) {
@ -1160,9 +1450,10 @@ class Validator
}
/**
* Add label to rule
*
* @param string $value
* @internal param array $labels
* @return $this
* @return Validator
*/
public function label($value)
{
@ -1173,8 +1464,10 @@ class Validator
}
/**
* Add labels to rules
*
* @param array $labels
* @return $this
* @return Validator
*/
public function labels($labels = array())
{
@ -1185,29 +1478,31 @@ class Validator
/**
* @param string $field
* @param string $msg
* @param string $message
* @param array $params
* @return array
*/
protected function checkAndSetLabel($field, $msg, $params)
protected function checkAndSetLabel($field, $message, $params)
{
if (isset($this->_labels[$field])) {
$msg = str_replace('{field}', $this->_labels[$field], $msg);
$message = str_replace('{field}', $this->_labels[$field], $message);
if (is_array($params)) {
$i = 1;
foreach ($params as $k => $v) {
$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;
$msg = str_replace($tag, $label, $msg);
$message = str_replace($tag, $label, $message);
$i++;
}
}
} else {
$msg = str_replace('{field}', ucwords(str_replace('_', ' ', $field)), $msg);
$message = $this->prepend_labels
? str_replace('{field}', ucwords(str_replace('_', ' ', $field)), $message)
: str_replace('{field} ', '', $message);
}
return $msg;
return $message;
}
/**
@ -1237,7 +1532,7 @@ class Validator
*
* @param array $data
* @param array $fields
* @return \Valitron\Validator
* @return Validator
*/
public function withData($data, $fields = array())
{
@ -1250,19 +1545,20 @@ class Validator
/**
* Convenience method to add validation rule(s) by field
*
* @param string field_name
* @param string $field
* @param array $rules
*/
public function mapFieldRules($field_name, $rules){
public function mapFieldRules($field, $rules)
{
$me = $this;
array_map(function($rule) use($field_name, $me){
array_map(function ($rule) use ($field, $me) {
//rule must be an array
$rule = (array)$rule;
//First element is the name of the rule
$rule_name = array_shift($rule);
$ruleName = array_shift($rule);
//find a custom message, if any
$message = null;
@ -1271,7 +1567,7 @@ class Validator
unset($rule['message']);
}
//Add the field and additional parameters to the rule
$added = call_user_func_array(array($me, 'rule'), array_merge(array($rule_name, $field_name), $rule));
$added = call_user_func_array(array($me, 'rule'), array_merge(array($ruleName, $field), $rule));
if (!empty($message)) {
$added->message($message);
}
@ -1283,10 +1579,16 @@ class Validator
*
* @param array $rules
*/
public function mapFieldsRules($rules){
public function mapFieldsRules($rules)
{
$me = $this;
array_map(function($field_name) use($rules, $me){
$me->mapFieldRules($field_name, $rules[$field_name]);
array_map(function ($field) use ($rules, $me) {
$me->mapFieldRules($field, $rules[$field]);
}, 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;
}
}

View File

@ -1,11 +1,11 @@
<?php
class BaseTestCase extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
}
use PHPUnit\Framework\TestCase;
class BaseTestCase extends TestCase
{
/*
public function tearDown()
{
$this->resetProperty('_lang');
@ -16,9 +16,10 @@ class BaseTestCase extends \PHPUnit_Framework_TestCase
protected function resetProperty($name, $value = null)
{
$prop = new ReflectionProperty('Valitron\Validator', $name);
$prop = new \ReflectionProperty('Valitron\Validator', $name);
$prop->setAccessible(true);
$prop->setValue($value);
$prop->setAccessible(false);
}
*/
}

View File

@ -1,4 +1,5 @@
<?php
use Valitron\Validator;
class ErrorMessagesTest extends BaseTestCase
@ -11,6 +12,19 @@ class ErrorMessagesTest extends BaseTestCase
$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()
{
$v = new Validator(array('num' => 5));
@ -66,7 +80,8 @@ class ErrorMessagesTest extends BaseTestCase
$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->rule('required', 'name')->label('my name');
$v->validate();

View File

@ -9,18 +9,18 @@ class LangTest extends BaseTestCase
}
/**
* Lang defined statically should not be overrided by constructor default
* Lang defined statically should not be override by constructor default
*/
public function testLangDefinedStatically()
{
$lang = 'ar';
Validator::lang($lang);
$validator = new Validator(array());
$this->assertEquals($lang, Validator::lang());
Validator::lang('en');
}
/**
* LangDir defined statically should not be overrided by constructor default
* LangDir defined statically should not be override by constructor default
*/
public function testLangDirDefinedStatically()
{
@ -42,12 +42,23 @@ class LangTest extends BaseTestCase
$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()
{
try{
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]);
}
}

View File

@ -1,12 +1,11 @@
<?php
use Valitron\Validator;
use Valitron\Validator;
class MapRulesTest extends BaseTestCase
{
public function testMapSingleFieldRules()
{
$rules = array(
'required',
array('lengthMin', 4)
@ -24,7 +23,6 @@ class MapRulesTest extends BaseTestCase
public function testSingleFieldDot()
{
$v = new Valitron\Validator(array(
'settings' => array(
array('threshold' => 50),
@ -36,7 +34,6 @@ class MapRulesTest extends BaseTestCase
));
$this->assertFalse($v->validate());
}
public function testMapMultipleFieldsRules()
@ -60,7 +57,6 @@ class MapRulesTest extends BaseTestCase
$this->assertFalse($v->validate());
$this->assertFalse($v->errors('myField1'));
$this->assertEquals(2, sizeof($v->errors('myField2')));
}
public function testCustomMessageSingleField()
@ -100,8 +96,6 @@ class MapRulesTest extends BaseTestCase
$errors1 = $v->errors('myField1');
$this->assertEquals('My Custom Error 1', $errors1[0]);
$errors2 = $v->errors('myField2');
$this->assertEquals('My Custom Error 2', $errors2[0]);
}

View File

@ -7,8 +7,10 @@ class StaticVsInstanceTest extends BaseTestCase
{
Validator::lang('ar');
new Validator(array(), array(), 'en');
$this->assertEquals('ar', Validator::lang(),
'instance defined lang should not replace static global lang');
$this->assertEquals(
'ar', Validator::lang(), 'instance defined lang should not replace static global lang'
);
Validator::lang('en');
}
/**

View File

@ -0,0 +1,28 @@
<?php
use Valitron\Validator;
class StopOnFirstFail extends BaseTestCase
{
public function testStopOnFirstFail()
{
$rules = array(
'myField1' => array(
array('lengthMin', 5, 'message' => 'myField1 must be 5 characters minimum'),
array('url', 'message' => 'myField1 is not a valid url'),
array('urlActive', 'message' => 'myField1 is not an active url')
)
);
$v = new Validator(array(
'myField1' => 'myVal'
));
$v->mapFieldsRules($rules);
$v->stopOnFirstFail(true);
$this->assertFalse($v->validate());
$errors = $v->errors();
$this->assertCount(1, $errors['myField1']);
}
}

View File

@ -1,4 +1,5 @@
<?php
use Valitron\Validator;
function callbackTestFunction($item, $value)
@ -8,14 +9,15 @@ function callbackTestFunction($item, $value)
class ValidateAddInstanceRuleTest extends BaseTestCase
{
/**
* @param Validator $v
*/
protected function assertValid($v)
{
$msg = "\tErrors:\n";
$status = $v->validate();
foreach ($v->errors() as $label => $messages)
{
foreach ($messages as $theMessage)
{
foreach ($v->errors() as $label => $messages) {
foreach ($messages as $theMessage) {
$msg .= "\n\t{$label}: {$theMessage}";
}
}
@ -30,13 +32,11 @@ class ValidateAddInstanceRuleTest extends BaseTestCase
"fuzz" => "bazz",
));
$v->addInstanceRule("fooRule", function($field, $value)
{
$v->addInstanceRule("fooRule", function ($field, $value) {
return $field !== "foo" || $value !== "barz";
});
Validator::addRule("fuzzerRule", function($field, $value)
{
Validator::addRule("fuzzerRule", function ($field, $value) {
return $field !== "fuzz" || $value === "bazz";
});
@ -50,8 +50,7 @@ class ValidateAddInstanceRuleTest extends BaseTestCase
public function testAddInstanceRuleFail()
{
$v = new Validator(array("foo" => "bar"));
$v->addInstanceRule("fooRule", function($field)
{
$v->addInstanceRule("fooRule", function ($field) {
return $field === "for";
});
$v->rule("fooRule", "foo");
@ -113,7 +112,8 @@ class ValidateAddInstanceRuleTest extends BaseTestCase
$this->assertEquals("foo_bar_rule", $v->getUniqueRuleName($args));
$this->assertEquals("foo_rule", $v->getUniqueRuleName("foo"));
$v->addInstanceRule("foo_rule", function() {});
$v->addInstanceRule("foo_rule", function () {
});
$u = $v->getUniqueRuleName("foo");
$this->assertRegExp("/^foo_rule_[0-9]{1,5}$/", $u);
}

File diff suppressed because it is too large Load Diff