1. Go to this page and download the library: Download iqomp/validator 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/ */
namespace MyModule\Module;
class Validator
{
public static function custom(
mixed $value,
mixed $options,
object $object,
string $fname,
array $rules
) {
// most of the time, the null value is for `a'=>'b']];
// return ['100.0', ['a'=>'b'], 'Error message'];
}
}
// ...
return [
'validator' => [
// error translation key
'errors' => [
'/code/' => '/translation key',
'100.0' => 'the value is not accepted'
],
'validators' => [
'custom' => 'MyModule\\Module\\Validator::custom'
]
]
];
// ...
return [
'the value is not accepted' => 'The value is not accepted.'
];
namespace MyModule\Module;
class Filter
{
public static function custom(
mixed $value,
mixed $options,
object $object,
string $fname,
array $rules
) {
// most of the time, it's not processed if it's null.
if (is_null($value)) {
return null;
}
// modify the $value;
return $value;
}
}