1. Go to this page and download the library: Download ivangrigorov/vmvalidator 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/ */
ivangrigorov / vmvalidator example snippets
use RMValidator\Attributes\PropertyAttributes\Collection\UniqueAttribute;
use RMValidator\Attributes\PropertyAttributes\File\FileExtensionAttribute;
use RMValidator\Attributes\PropertyAttributes\File\FileSizeAttribute;
use RMValidator\Attributes\PropertyAttributes\Numbers\RangeAttribute;
use RMValidator\Attributes\PropertyAttributes\Object\NestedAttribute;
use RMValidator\Attributes\PropertyAttributes\Strings\StringContainsAttribute;
use RMValidator\Enums\ValidationOrderEnum;
use RMValidator\Options\OptionsModel;
use RMValidator\Validators\MasterValidator;
izeLowest: 10)]
#[FileExtensionAttribute(expected:['php'])]
public string $file = __FILE__;
#[StringContainsAttribute(needle:"asd")]
public string $string = "23asd";
#[RangeAttribute(from:10, to:30)]
public int $prop = 40;
}
class UpperTest
{
#[NestedAttribute(excludedProperties:['param'])]
private Test $test;
public function __construct(Test $test) {
$this->test = $test;
}
}
$test = new Test(40);
try {
MasterValidator::validate(new UpperTest($test),
new OptionsModel(orderOfValidation: [ValidationOrderEnum::PROPERTIES,
ValidationOrderEnum::METHODS,
ValidationOrderEnum::CONSTANTS],
excludedMethods: ['getFile'],
excludedProperties: ['file']));
} catch(Exception $e) {
var_dump($e);
}
class Validation
{
public static function validate($valueToTest, $arg1): bool
{
return $valueToTest == $arg1;
}
}