1. Go to this page and download the library: Download meraki/schema 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/ */
use Meraki\Schema\Definition;
$schema = new Definition('contact_form');
$schema->add(
$schema->createTextField('username')->minLengthOf(3)->maxLengthOf(20),
$schema->createEmailAddressField('email'),
);
$schema->validate((object) [
'price' => (object) ['currency' => 'AUD', 'amount' => '12.50'], // a record
'lines' => [$row, $row], // a list
]);
$result = $schema->validate($data);
$result->anyFailed(); // any field failed
$result->allPassed(); // every field passed
$field = $result->forField('email');
$field->given; // exactly what was submitted, unchanged
$field->value; // what the field made of it — an EmailAddress\Value
$field->source; // Submitted | Prefilled | Default | None
$field->shape; // could this be read at all?
$field->status; // Passed | Failed | Skipped | Pending
$failed = $field->getFailedConstraints()->getFirst();
$failed->name; // 'minLength'
$failed->bound; // 3
$failed->part; // 'postal_code', or null for the whole value
use Meraki\Schema\Message\Mf2\Mf2Provider;
$provider = Mf2Provider::fromPackage('meraki/schema-language-english');
$result = $schema->validate($data, locale: 'en-AU', messages: $provider);
$result->forField('billing')->messages->forPart('postal_code')->first;
// "That is not a valid postcode for the country you chose."
$schema = (new Definition('booking'))->for('AU');
$schema->createAddressField('billing'); // restricted to AU
$schema->createPhoneNumberField('mobile'); // ditto
$age->when()->isAtLeast(18); // 18 passes
$age->when()->isGreaterThan(18); // 18 does not
$age->when()->isBetween(18, 65); // both ends
use Meraki\Schema\ValueScope;
// is the shipping address the billing address?
$schema->when(ValueScope::of('shipping'))->equals(ValueScope::of('billing'));
// are they at least in the same country?
$schema->when(ValueScope::of('shipping', 'country'))
->equals(ValueScope::of('billing', 'country'));
$schema = new Definition('signup'); // built once, at boot
// ...
$alice = $schema->validate($a); // two requests, in any order,
$mallory = $schema->validate($b); // interleaved or not