phillipsdata / minphp-input Goto Github PK
View Code? Open in Web Editor NEWInput Validation Library
Input Validation Library
The update from #5 should be updated from:
if (!array_key_exists($index, $data_set)) {
$data_set = null;
break;
}
to
if (!array_key_exists($index, $data_set)) {
continue 2;
}
This accurately keeps the $param
null (line 460), and also does not override the $data_set
with null. That is, we do not want the $data_set
to be null for the _linked parameter that is set to null, but rather we want the $data_set
to remain unchanged and the _linked parameter to be intepretted as null.
The difference is noticable when we link array fields, e.g.:
$rules = array(
'test[][value]' => array(
'invalid' => array(
'rule' => array(
function ($value, $option) {
return true;
},
array('_linked' => 'test[][option]')
),
'message' => 'Test'
)
)
);
$vars = array('test' => array(array('value' => 1)));
$input = new Input();
$input->setRules($rules);
$input->validates($vars);
print_r($vars);
The printed output of $vars
is
array(
'test' => array(
array(
'value' => 1
'option' => null
)
)
)
This causes $vars['test'][0]
to contain an option
key, set to null, that it should not have. This task would resolve that issue.
According to RFC1034, each label in a hostname may be up to 63 octets long.
When validating rules, or setting pre/post formatting, "_linked" fields can be included and past along to a callback function. However, if the field referenced via "_linked" is not set in the input array being validated against, then the value of the field is set to the entire input array. Instead, the value should be null since it is not set.
e.g.
$rules = [
'test' => [
'invalid' => [
'rule' => [
function ($test, $option) {
var_dump($test); // 'abc'
var_dump($option); // ['test' => 'abc', 'x' => 100, 'y' => 200]
return false;
},
['_linked' => 'option']
],
'message' => 'Test Error'
]
]
];
$data = ['test' => 'abc', 'x' => 100, 'y' => 200];
$input = new Input();
$input->setRules($rules);
$input->validates($data);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.