<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
alleyinteractive / laminas-validator-extensions example snippets
class Float extends \Laminas\Validator\AbstractValidator
{
const FLOAT = 'float';
protected $messageTemplates = [
self::FLOAT => "'%value%' is not a floating point value",
];
public function isValid($value)
{
$this->setValue($value);
if (! is_float($value)) {
$this->error(self::FLOAT);
return false;
}
return true;
}
}
class Float extends \Alley\Validator\ExtendedAbstractValidator
{
const FLOAT = 'float';
protected $messageTemplates = [
self::FLOAT => "'%value%' is not a floating point value",
];
public function testValue($value): void
{
if (! is_float($value)) {
$this->error(self::FLOAT);
}
}
}
class Float extends \Alley\Validator\FreeformValidator
{
public function testValue($value): void
{
if (! is_float($value)) {
$this->error('float', 'Please enter a floating point value');
}
}
}
$origin = new \Alley\Validator\OneOf(['haystack' => ['foo', 'bar']]);
$valid = new \Alley\Validator\Not($origin, 'The input was invalid.');
$valid->isValid('foo'); // false
$valid->isValid('baz'); // true
$valid = new \Alley\Validator\OneOf(['haystack' => ['one', 'two', 'three']]);
$valid->isValid('four'); // false
$valid->getMessages(); // ['notOneOf' => 'Must be one of [one, two, three] but is four.']
$valid = new \Alley\Validator\Type(['type' => 'callable']);
$valid->isValid('date_create_immutable'); // true
$valid = new \Alley\Validator\Type(['type' => 'bool']);
$valid->isValid([]); // false
$origin = new \Laminas\Validator\GreaterThan(42);
$valid = new \Alley\Validator\WithMessage('tooSmall', 'Please enter a number greater than 42.', $origin);
$valid->isValid(41); // false
$valid->getMessages(); // ['tooSmall' => 'Please enter a number greater than 42.']
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.