1. Go to this page and download the library: Download mizmoz/validate library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$result = Validate::isSame('me')
->toValue(\User::current()->userId)
->validate($userId);
// get the user id
$userId = $result->getValue();
// Validate a set of items
$result = Validate::set([
'name' => Validate::isString()
->setDescription('Subscriber name')
->isRequired(),
'email' => Validate::isEmail()
->isRequired(),
'sendNewsletter' => Validate::isBoolean()
->setDescription('Subscribe the email address to the newsletter?')
->setDefault(false)
])->validate($_POST);
// Get the sanitised data as an array.
$values = $result->getValue();
// Add custom validator
ValidateFactory::setHelper('aclOwner', function () {
// add your custom validator
return new IsOwner();
});
Validate::aclAuthenticated(\User::current())->validate(\User::get(1));
# Setup the Mock of isString
$mock = ValidatorFactory::mock('isString')
->valid(false)
->value('fail-value')
->message('boo');
Validator::isString()->validate('hello')->isValid(); // false as we've overriden the result
# Reset the container
ValidatorFactory::unMock('isString');
# ... or using the original mock
$mock->unMock();
# You can also make a mock go away after it's called by adding `once()` when setting it up
ValidatorFactory::mock('isString')
// ... extra setup
->once();
# return an array with the param names and the called method either __constructor, validate or resolve
$mock->getCallArguments();
$validate = new IsFilter([
'#active|#deleted' => 'userStatus'
]);
$result = $validate->validate('#deleted')->getValue(); // returns ['userStatus' => ['delete'], 'filter' => '']
$model = User::create();
foreach ($result as $column => $value) {
// we have some magic attached to our models for filtering also but you get the idea of how this can be used ;)
$model->where($column, $value);
}
$model->fetch();
// active is marked as the default
$validate = new IsFilter([
'#active*|#inactive' => 'status'
]);
$validate->validate('')->getValue(); // returns ['status' => ['active']]
// Or with a filter
$validate->validate('Bob')->getValue(); // returns ['status' => ['active'], 'filter' => 'Bob']
// active is marked as the default
$validate = new IsFilter([
'#active*|#inactive' => 'status',
'#admin|#user' => 'role',
]);
$validate->validate('')->getValue(); // returns ['status' => ['active']]
// Or with a tag
$validate->validate('#admin')->getValue(); // returns ['status' => ['active'], 'role' => ['admin']]
(new IsInteger())
->validate(1); // valid
(new IsNumeric())
->validate(1); // valid
(new IsNumeric())
->validate('100'); // valid
(new IsReCaptcha($secret))
->validate($response);
(new IsShape([
'name' => new IsString(),
'age' => new IsInteger(),
]))->validate([
'name' => 'Bob',
'age' => 45,
]); // valid
$validate = Validate::set([
'name' => Validate::isString()
->setDescription('Full name')
->isRequired(),
]);
// return an array describing the set / shape.
$validate->getDescription();
(new IsString)
->validate('Hello world'); // valid
// Positive match
Validate::is()->email();
// Negative match
Validate::not()->email();
php bin/mizmoz update
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.