1. Go to this page and download the library: Download imarc/checkpoint 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/ */
imarc / checkpoint example snippets
class CustomInspector extends Checkpoint\Inspector
{
protected function validate($data)
{
//
// Your validation logic here
//
}
}
$custom_inspector = new CustomInspector();
$custom_inspector->setValidator(new Respect\Validation\Validator());
public function __construct(PeopleRepository $people)
{
$this->people = $people;
}
public function validate($data)
{
if ($this->people->findOneByEmail($data['email'])) {
$this->log('email', 'The e-mail address must be unique in our system.');
}
}
public function validate($data)
{
$this->check('firstName', $data['firstName'], ['notBlank']);
}
public function validate($data)
{
$this->check('firstName', $data->getFirstName(), ['notBlank']);
}
public function validate($data)
{
$this->define('descLength', 'Please enter a description of at least 100 characters.')
-> length(100);
$this->check('description', $data['description'], ['descLength']);
}
$person = new Person();
$person->setFirstName('Matthew');
$person->setLastName('Sahagian');
...
$person_inspector->run($person)
class ProfileInspector extends Checkpoint\Inspector
{
public function __construct(PeopleRepository $people, PersonInspector $pinspector, CompanyInspector $cinspector)
{
$this->people = $people;
$this->add('person', $pinspector);
$this->add('company', $cinspector);
}
protected function validate($data)
{
if ($this->people->findOneByEmail($data['person']['email'])) {
$this->log('duplicate', TRUE);
return;
}
$this->fetch('person')->run($data['person']);
$this->fetch('company')->run($data['company']);
}
}
class CompanyInspector extends Checkpoint\Inspector
{
protected function validate($data)
{
$this->define('zipCode', 'Please enter a valid zipcode for the US')
->postalCode('US');
$this
->check('name', $data['name'], ['notBlank'])
->check('address', $data['address'], ['notBlank'])
->check('city', $data['city'], ['notBlank'])
->check('state', $data['state'], ['notBlank'])
->check('zipCode', $data['zipCode'], ['zipCode'])
;
}
}
$profile_inspector = new ProfileInspector(new PeopleRepository, new PersonInspector, new CompanyInspector);
$profile_inspector->run([
'person' => [
'firstName' => 'Matthew',
'lastName' => 'Sahagian'
],
'company' => [
'name' => 'Imarc LLC',
'address' => '111 1/2 Cooper Street',
'city' => 'Santa Cruz',
'state' => 'CA',
'zipCode' => '95060'
]
]);
if ($profile_inspector->countMessages()) {
throw new Checkpoint\ValidationException('Please correct the errors below.');
}
{% if inspector.messages('duplicate') %}
<div class="error">
<p>
The e-mail you are trying to use is already taken by another person in our system. If you are the
owner of that account, you may want to try <a href="/forgot-password">recovering your account</a>.
</p>
</div>
{% endif %}