1. Go to this page and download the library: Download runz0rd/mapper-php 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/ */
runz0rd / mapper-php example snippets
class SomeGuy {
/**
* @ublic $name;
/**
* @rule limit(1,150)
* @var integer
*/
public $age;
/**
* @var boolean
*/
public $isEmployed;
/**
* @name custom-desc
* @var string
*/
public $description
}
$mapper = new ModelMapper();
$myObject = $mapper->unmap($myModel);
$model->validate('createAction');
$model->validate();
$model = new Model();
$validator = new ModelValidator();
$validator->validate($model, 'myAction');
/**
* @rule email
*/
public $email;
/**
* @rule limit(0,99)
*/
public $value;
use Common\ModelReflection\ModelProperty;
use Validator\IRule;
use Validator\ModelValidatorException;
class LimitRule implements IRule {
function getNames() {
return ['limit'];
}
function validate(ModelProperty $property, array $params = []) {
if($property->getPropertyValue() < $params[0] || $property->getPropertyValue() > $params[1]) {
throw new ModelValidatorException('Value is not between '.$params[0].' and '.$params[1]);
}
}
}
$model = new Model();
$myCustomRule = new MyCustomRule();
$validator = new ModelValidator();
$validator->useRule($myCustomRule);
$validator->loadRules('/path/to/rules/');
$validator->validate($model, 'myAction');
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.