Added vendor/ directory for Composer's installed files
This commit is contained in:
32
vendor/alexgarrett/violin/examples/rules/custom_rule.php
vendored
Executable file
32
vendor/alexgarrett/violin/examples/rules/custom_rule.php
vendored
Executable file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Violin example. Custom rule.
|
||||
*
|
||||
* Creating a custom rule using the addRule method, passing in a
|
||||
* closure which should return false if the check has failed,
|
||||
* or true if the check has passed.
|
||||
*/
|
||||
|
||||
require '../vendor/autoload.php';
|
||||
|
||||
use Violin\Violin;
|
||||
|
||||
$v = new Violin;
|
||||
|
||||
$v->addRuleMessage('startsWithNumber', 'The {field} must start with a number.');
|
||||
|
||||
$v->addRule('startsWithNumber', function($value, $input, $args) {
|
||||
$value = trim($value);
|
||||
return is_numeric($value[0]);
|
||||
});
|
||||
|
||||
$v->validate([
|
||||
'username' => ['dale', 'required|min(3)|max(20)|startsWithNumber']
|
||||
]);
|
||||
|
||||
if ($v->passes()) {
|
||||
// Passed
|
||||
} else {
|
||||
var_dump($v->errors()->all());
|
||||
}
|
35
vendor/alexgarrett/violin/examples/rules/custom_rule_arguments.php
vendored
Executable file
35
vendor/alexgarrett/violin/examples/rules/custom_rule_arguments.php
vendored
Executable file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Violin example. Custom rule.
|
||||
*
|
||||
* Creating a custom rule using the addRule method, passing in a
|
||||
* closure which should return false if the check has failed,
|
||||
* or true if the check has passed.
|
||||
*
|
||||
* This example shows the use of arguments that can be used
|
||||
* to make rules that require arguments.
|
||||
*/
|
||||
|
||||
require '../vendor/autoload.php';
|
||||
|
||||
use Violin\Violin;
|
||||
|
||||
$v = new Violin;
|
||||
|
||||
$v->addRuleMessage('startsWith', 'The {field} must start with "{$0}".');
|
||||
|
||||
$v->addRule('startsWith', function($value, $input, $args) {
|
||||
$value = trim($value);
|
||||
return $value[0] === $args[0];
|
||||
});
|
||||
|
||||
$v->validate([
|
||||
'username' => ['dale', 'required|min(3)|max(20)|startsWith(a)']
|
||||
]);
|
||||
|
||||
if ($v->passes()) {
|
||||
// Passed
|
||||
} else {
|
||||
var_dump($v->errors()->all());
|
||||
}
|
Reference in New Issue
Block a user