1. Go to this page and download the library: Download everest/validation 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/ */
everest / validation example snippets
use Everest\Validation\Validation;
$int = Validation::integer('10'); // $int -> 10
$noint = Validation::integer('foo'); // Will throw \Everest\Validation\InvalidValidationException
class CustomType extends \Everest\Validation\Types\Type {
public static $errorName = 'invalid_custom_error';
public static $errorMessage = '%s is not a valid custom type.';
public function __invoke($value, $message = null, string $key = null, $customArg1 = null, $customArg2 = null)
{
if (/* Your invalid condition here */) {
$message = sprintf(
self::generateErrorMessage($message ?: self::$errorMessage),
self::stringify($value)
);
throw new InvalidValidationException(self::$errorName, $message, $key, $value);
}
/**
* You may transform/cast the result before retuning it.
* In this case it is usefull to add a custom argument as
* `$doCast` = false flag
*/
return $value;
}
}
// Add as class. A singleton instance will be created when the type is requested the first time
\Everest\Validation\Validation::addType('custom_name', CustomType::CLASS);
// Add as instance. You can also supply a instance of your custom type.
// E.g. when you need to do some configuration in `__construct()`
\Everest\Validation\Validation::addType('custom_name', new CustomType());
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.