1. Go to this page and download the library: Download guide42/plan 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/ */
$plan = new Schema(array(
'Connection' => v\any('ethernet', 'wireless'),
));
$plan(array('Connection' => 'ethernet'));
$plan(array('Connection' => 'wireless'));
try {
$plan(array('Connection' => 'any'));
} catch (MultipleInvalid $errors) {
assert('{ [Connection]: No valid value found }' === $errors->getMessage());
}
$plan = new Schema(v\all(v\str(), v\length(3, 17)));
$plan('Hello World');
try {
$plan('No');
} catch (MultipleInvalid $errors) {
assert('[ Value must be at least 3 ]' === $errors->getMessage());
}
$plan = new Schema(v\length(2, 4));
$plan('abc');
$plan(['a', 'b', 'c']);
try {
$plan('hello');
} catch (MultipleInvalid $errors) {
assert('[ Value must be at most 4 ]' === $errors->getMessage());
}
$lower = true; // all lower-case characters
$upper = true; // all upper-case characters
$number = true; // all numbers
$whitespace = true; // the only one not language dependant
$plan = new Schema(f\intl\chars($lower, $upper, $number, $whitespace));
$data = $plan('Hello World ☃!!1');
assert('Hello World 1' === $data);
$passwordStrength = function($data, $path = null)
{
$type = v\str(); // Use another validator to check that `$data` is
$data = $type($data); // an string, if not will throw an exception.
// Because we are going to throw more than one error, we will
// accumulate in this variable.
$errors = [];
if (strlen($data) < 8) {
$errors[] = new Invalid('Must be at least 8 characters');
}
if (!preg_match('/[A-Z]/', $data)) {
$errors[] = new Invalid('Must have at least one uppercase letter');
}
if (!preg_match('/[a-z]/', $data)) {
$errors[] = new Invalid('Must have at least one lowercase letter');
}
if (!preg_match('/\d/', $data)) {
$errors[] = new Invalid('Must have at least one digit');
}
if (count($errors) > 0) {
throw new MultipleInvalid($errors);
}
// If everything went OK, we return the data so it can continue to be
// checked by the chain.
return $data;
};
$validator = new Schema(v\all(v\str(), $passwordStrength, v\not('hunter2')));
$validated = $validator('heLloW0rld');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.