Dep: update
주로 PHAN
This commit is contained in:
@@ -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
|
||||
Vendored
+44
-16
@@ -6,10 +6,12 @@ methods with a focus on readable and concise syntax. Valitron is the
|
||||
simple and pragmatic validation library you've been looking for.
|
||||
|
||||
[](https://travis-ci.org/vlucas/valitron)
|
||||
Status](https://github.com/vlucas/valitron/actions/workflows/test.yml/badge.svg)](https://github.com/vlucas/valitron/actions/workflows/test.yml)
|
||||
[](https://packagist.org/packages/vlucas/valitron)
|
||||
[](https://packagist.org/packages/vlucas/valitron)
|
||||
|
||||
[Get supported vlucas/valitron with the Tidelift Subscription](https://tidelift.com/subscription/pkg/packagist-vlucas-valitron?utm_source=packagist-vlucas-valitron&utm_medium=referral&utm_campaign=readme)
|
||||
|
||||
## Why Valitron?
|
||||
|
||||
Valitron was created out of frustration with other validation libraries
|
||||
@@ -125,6 +127,33 @@ V::lang('ar');
|
||||
|
||||
```
|
||||
|
||||
Disabling the {field} name in the output of the error message.
|
||||
|
||||
```php
|
||||
use Valitron\Validator as V;
|
||||
|
||||
$v = new Valitron\Validator(['name' => 'John']);
|
||||
$v->rule('required', ['name']);
|
||||
|
||||
// Disable prepending the labels
|
||||
$v->setPrependLabels(false);
|
||||
|
||||
// Error output for the "false" condition
|
||||
[
|
||||
["name"] => [
|
||||
"is required"
|
||||
]
|
||||
]
|
||||
|
||||
// Error output for the default (true) condition
|
||||
[
|
||||
["name"] => [
|
||||
"name is required"
|
||||
]
|
||||
]
|
||||
|
||||
```
|
||||
|
||||
You can conditionally require values using required conditional rules. In this example, for authentication, we're requiring either a token when both the email and password are not present, or a password when the email address is present.
|
||||
```php
|
||||
// this rule set would work for either data set...
|
||||
@@ -438,24 +467,19 @@ $v->rules([
|
||||
$v->validate();
|
||||
```
|
||||
|
||||
*Note* the optional boolean flag for strict mode will allow for integers to be supplied as negative values. So the following rule would evaluate to true:
|
||||
*Note* the optional boolean flag for strict mode makes sure integers are to be supplied in a strictly numeric form. So the following rule would evaluate to true:
|
||||
```php
|
||||
$v = new Valitron\Validator(['age' => '-27']);
|
||||
$v->rules([
|
||||
'integer' => [
|
||||
['age', true]
|
||||
]
|
||||
]);
|
||||
$v = new Valitron\Validator(['negative' => '-27', 'positive'=>'27']);
|
||||
$v->rule('integer', 'age', true);
|
||||
$v->rule('integer', 'height', true);
|
||||
$v->validate();
|
||||
```
|
||||
Whereas the same for a positive (+) value would evaluate to false, as the + in this case is redundant:
|
||||
|
||||
Whereas the following will evaluate to false, as the + for the positive number in this case is redundant:
|
||||
```php
|
||||
$v = new Valitron\Validator(['age' => '+27']);
|
||||
$v->rules([
|
||||
'integer' => [
|
||||
['age', true]
|
||||
]
|
||||
]);
|
||||
$v = new Valitron\Validator(['negative' => '-27', 'positive'=>'+27']);
|
||||
$v->rule('integer', 'age', true);
|
||||
$v->rule('integer', 'height', true);
|
||||
$v->validate();
|
||||
```
|
||||
|
||||
@@ -1121,7 +1145,7 @@ $v = new Valitron\Validator([
|
||||
'city' => 'Doe D.C.'
|
||||
]
|
||||
]);
|
||||
$v->rule(['arrayHasKeys', 'address', ['name', 'street', 'city']);
|
||||
$v->rule('arrayHasKeys', 'address', ['name', 'street', 'city']);
|
||||
$v->validate();
|
||||
```
|
||||
|
||||
@@ -1324,3 +1348,7 @@ before running the tests:
|
||||
6. Push to the branch (`git push origin my-new-feature`)
|
||||
7. Create new Pull Request
|
||||
8. Pat yourself on the back for being so awesome
|
||||
|
||||
## Security Disclosures and Contact Information
|
||||
|
||||
To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
|
||||
|
||||
Vendored
+3
-3
@@ -3,20 +3,20 @@
|
||||
"type": "library",
|
||||
"description": "Simple, elegant, stand-alone validation library with NO dependencies",
|
||||
"keywords": ["validation", "validator", "valid"],
|
||||
"homepage": "http://github.com/vlucas/valitron",
|
||||
"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.8.35 || ^5.5 || ^6.5"
|
||||
"phpunit/phpunit": ">=4.8.35"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-mbstring": "It can support the multiple bytes string length."
|
||||
|
||||
Vendored
+37
-32
@@ -1,35 +1,40 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'required' => "est obligatoire",
|
||||
'equals' => "doit être identique à '%s'",
|
||||
'different' => "doit être différent de '%s'",
|
||||
'accepted' => "doit être accepté",
|
||||
'numeric' => "doit être numérique",
|
||||
'integer' => "doit être un entier",
|
||||
'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",
|
||||
'email' => "n'est pas une adresse email valide",
|
||||
'url' => "n'est pas une URL",
|
||||
'urlActive' => "doit être un domaine actif",
|
||||
'alpha' => "doit contenir uniquement les lettres a-z",
|
||||
'alphaNum' => "doit contenir uniquement des lettres de a-z et/ou des chiffres 0-9",
|
||||
'slug' => "doit contenir uniquement des lettres de a-z, des chiffres 0-9, des tirets et des traits soulignés",
|
||||
'regex' => "contient des caractères invalides",
|
||||
'date' => "n'est pas une date valide",
|
||||
'dateFormat' => "doit être une date avec le format '%s'",
|
||||
'dateBefore' => "doit être une date avant '%s'",
|
||||
'dateAfter' => "doit être une date après '%s'",
|
||||
'contains' => "doit contenir %s",
|
||||
'boolean' => "doit être un booléen",
|
||||
'lengthBetween' => "doit être entre %d et %d caractères",
|
||||
'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'"
|
||||
return array(
|
||||
'required' => "est obligatoire",
|
||||
'equals' => "doit être identique à '%s'",
|
||||
'different' => "doit être différent de '%s'",
|
||||
'accepted' => "doit être accepté",
|
||||
'numeric' => "doit être numérique",
|
||||
'integer' => "doit être un entier",
|
||||
'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",
|
||||
'email' => "n'est pas une adresse email valide",
|
||||
'url' => "n'est pas une URL",
|
||||
'urlActive' => "doit être un domaine actif",
|
||||
'alpha' => "doit contenir uniquement les lettres a-z",
|
||||
'alphaNum' => "doit contenir uniquement des lettres de a-z et/ou des chiffres 0-9",
|
||||
'slug' => "doit contenir uniquement des lettres de a-z, des chiffres 0-9, des tirets et des traits soulignés",
|
||||
'regex' => "contient des caractères invalides",
|
||||
'date' => "n'est pas une date valide",
|
||||
'dateFormat' => "doit être une date avec le format '%s'",
|
||||
'dateBefore' => "doit être une date avant '%s'",
|
||||
'dateAfter' => "doit être une date après '%s'",
|
||||
'contains' => "doit contenir %s",
|
||||
'boolean' => "doit être un booléen",
|
||||
'lengthBetween' => "doit être entre %d et %d caractères",
|
||||
'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'",
|
||||
"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"
|
||||
);
|
||||
|
||||
Vendored
+42
@@ -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",
|
||||
);
|
||||
+1
-1
@@ -7,7 +7,7 @@ return array(
|
||||
'accepted' => "必须接受",
|
||||
'numeric' => "只能是数字",
|
||||
'integer' => "只能是整数",
|
||||
'length' => "长度必须大于 %d",
|
||||
'length' => "长度必须等于 %d",
|
||||
'min' => "必须大于 %s",
|
||||
'max' => "必须小于 %s",
|
||||
'listContains' => "无效的值",
|
||||
|
||||
+65
-31
@@ -83,6 +83,11 @@ class Validator
|
||||
*/
|
||||
protected $stop_on_first_fail = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $prepend_labels = true;
|
||||
|
||||
/**
|
||||
* Setup validation
|
||||
*
|
||||
@@ -144,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
|
||||
*
|
||||
@@ -159,9 +172,7 @@ class Validator
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -409,9 +420,13 @@ class Validator
|
||||
*/
|
||||
protected function validateIn($field, $value, $params)
|
||||
{
|
||||
$isAssoc = array_values($params[0]) !== $params[0];
|
||||
if ($isAssoc) {
|
||||
$params[0] = array_keys($params[0]);
|
||||
$forceAsAssociative = false;
|
||||
if (isset($params[2])) {
|
||||
$forceAsAssociative = (bool) $params[2];
|
||||
}
|
||||
|
||||
if ($forceAsAssociative || $this->isAssociativeArray($params[0])) {
|
||||
$params[0] = array_keys($params[0]);
|
||||
}
|
||||
|
||||
$strict = false;
|
||||
@@ -432,8 +447,12 @@ class Validator
|
||||
*/
|
||||
protected function validateListContains($field, $value, $params)
|
||||
{
|
||||
$isAssoc = array_values($value) !== $value;
|
||||
if ($isAssoc) {
|
||||
$forceAsAssociative = false;
|
||||
if (isset($params[2])) {
|
||||
$forceAsAssociative = (bool) $params[2];
|
||||
}
|
||||
|
||||
if ($forceAsAssociative || $this->isAssociativeArray($value)) {
|
||||
$value = array_keys($value);
|
||||
}
|
||||
|
||||
@@ -616,7 +635,8 @@ class Validator
|
||||
if (function_exists('idn_to_ascii') && defined('INTL_IDNA_VARIANT_UTS46')) {
|
||||
$domain = idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46);
|
||||
}
|
||||
return checkdnsrr($domain, 'ANY');
|
||||
|
||||
return checkdnsrr($domain, 'MX');
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -877,11 +897,9 @@ 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;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -1089,10 +1107,8 @@ class Validator
|
||||
}
|
||||
}
|
||||
// Use custom label instead of field name if set
|
||||
if (is_string($params[0])) {
|
||||
if (isset($this->_labels[$param])) {
|
||||
$param = $this->_labels[$param];
|
||||
}
|
||||
if (is_string($params[0]) && isset($this->_labels[$param])) {
|
||||
$param = $this->_labels[$param];
|
||||
}
|
||||
$values[] = $param;
|
||||
}
|
||||
@@ -1167,6 +1183,27 @@ class Validator
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
*
|
||||
@@ -1179,15 +1216,7 @@ class Validator
|
||||
foreach ($v['fields'] as $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 and we don't have a conditionally required rule present on the field
|
||||
if (($this->hasRule('optional', $field) && isset($values))
|
||||
|| ($this->hasRule('requiredWith', $field) || $this->hasRule('requiredWithout', $field))) {
|
||||
//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;
|
||||
}
|
||||
|
||||
@@ -1265,10 +1294,8 @@ class Validator
|
||||
protected function hasRule($name, $field)
|
||||
{
|
||||
foreach ($this->_validations as $validation) {
|
||||
if ($validation['rule'] == $name) {
|
||||
if (in_array($field, $validation['fields'])) {
|
||||
return true;
|
||||
}
|
||||
if ($validation['rule'] == $name && in_array($field, $validation['fields'])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1458,7 +1485,9 @@ class Validator
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$message = str_replace('{field}', ucwords(str_replace('_', ' ', $field)), $message);
|
||||
$message = $this->prepend_labels
|
||||
? str_replace('{field}', ucwords(str_replace('_', ' ', $field)), $message)
|
||||
: str_replace('{field} ', '', $message);
|
||||
}
|
||||
|
||||
return $message;
|
||||
@@ -1545,4 +1574,9 @@ class Validator
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user