本文整理汇总了PHP中AbstractValidator类的典型用法代码示例。如果您正苦于以下问题:PHP AbstractValidator类的具体用法?PHP AbstractValidator怎么用?PHP AbstractValidator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AbstractValidator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testNumbers
/**
* @test
*/
public function testNumbers()
{
foreach ($this->getValidNumbers() as $number) {
$this->assertTrue($this->validator->isValid($number));
}
foreach ($this->getInvalidNumbers() as $number) {
$this->assertFalse($this->validator->isValid($number));
}
}
示例2: validate
/**
* @param string $name
* @param string $value
* @param bool $stopOnError
*
* @return bool
*/
public function validate($name, $value, $stopOnError = false)
{
$this->errors = [];
if (null === $this->validator) {
$this->validator = ValidatorFactory::create($name, $this->type, $this->rules);
}
$isValid = $this->validator->validate($value, $stopOnError);
if (false === $isValid) {
$this->errors = $this->validator->getErrors();
}
return $isValid;
}
示例3: init
public function init()
{
if ($this->enableIDN && !function_exists('idn_to_ascii')) {
$this->addError($this->intlErrorMessage);
}
parent::init();
}
示例4: __construct
/**
* Do our own constructor so we can check for the php-clamav library
* @param \Foundation\Form\Element $e the element we are validating
* @param integer $sizeInBytes
*/
public function __construct(\Foundation\Form\Element $element)
{
if (!extension_loaded('clamav') or !function_exists('cl_scanfile')) {
throw new \Foundation\Exception("Virusscan validator requires the php-clamav extension.");
}
parent::__construct($element);
}
示例5: __construct
/**
* Construct
* Check the ruleSet
* @param \Foundation\Form\Element $e
* @param mixed $ruleSet
*/
public function __construct(\Foundation\Form\Element $e, $ruleSet)
{
if (!\is_array($ruleSet) or !isset($ruleSet[0]) or !isset($ruleSet[1])) {
throw new \Foundation\Exception("The ruleset for NumberRange must be an array with two elements.");
}
parent::__construct($e, $ruleSet);
}
示例6: __construct
/**
* @param null $options - expects to find a ['token'] entry in
* options, with the token in it
*/
public function __construct($options = null)
{
parent::__construct($options);
$this->setMessage(self::MsgInvalidToken, 'Unable to authenticate form data. Please refresh and try again.');
$this->token = isset($options['token']) ? $options['token'] : 'missing token';
$this->logger = isset($options['logger']) ? $options['logger'] : null;
}
示例7: __construct
/**
* Constructor
*
* @param array|callable $options
*/
public function __construct($options = null)
{
if (is_callable($options)) {
$options = ['callback' => $options];
}
parent::__construct($options);
}
示例8: init
public function init()
{
if ($this->message === null) {
switch ($this->operator) {
case '==':
$this->message = '{compareAttribute} must be repeated exactly.';
break;
case '===':
$this->message = '{compareAttribute} must be repeated exactly.';
break;
case '!=':
$this->message = '{compareAttribute} must not be equal to "{compareValue}".';
break;
case '!==':
$this->message = '{compareAttribute} must not be equal to "{compareValue}".';
break;
case '>':
$this->message = '{compareAttribute} must be greater than "{compareValue}".';
break;
case '>=':
$this->message = '{compareAttribute} must be greater than or equal to "{compareValue}".';
break;
case '<':
$this->message = '{compareAttribute} must be less than "{compareValue}".';
break;
case '<=':
$this->message = '{compareAttribute} must be less than or equal to "{compareValue}".';
break;
default:
$this->addError('Unknown operator: {operator}', ['{operator}' => $this->operator]);
}
}
parent::init();
}
示例9: __construct
/**
* Construct
* Check the ruleSet
* @param \Foundation\Form\Element $e
* @param mixed $ruleSet
*/
public function __construct(\Foundation\Form\Element $e, $ruleSet)
{
if (!\is_int($ruleSet)) {
throw new \Foundation\Exception("The ruleset for MaximumLength must be an integer");
}
parent::__construct($e, $ruleSet);
}
示例10: sanitize
/**
* {@inheritdoc}
*/
public function sanitize()
{
if ($this->canSanitize()) {
return new \DateTime($this->getInput());
}
return parent::sanitize();
}
示例11: init
public function init()
{
if (!is_array($this->range)) {
throw new \InvalidArgumentException($this->rangeErrorMessage);
}
parent::init();
}
示例12: __construct
/**
* Construct
* Check the ruleSet
*
* @param \Foundation\Form\Element $e
* @param mixed $ruleSet
*/
public function __construct(\Foundation\Form\Element $e, $ruleSet)
{
if (!\strtotime($ruleSet)) {
throw new \Foundation\Exception("The ruleset for DateBefore must be a valid PHP date string");
}
parent::__construct($e, $ruleSet);
}
示例13: __construct
/**
* Construct
* Check the ruleSet
*
* @param \Foundation\Form\Element $e
* @param mixed $ruleSet
*/
public function __construct(\Foundation\Form\Element $e, $ruleSet)
{
if (\is_null($ruleSet)) {
throw new \Foundation\Exception("The ruleset for SpeicifcString must be set.");
}
parent::__construct($e, $ruleSet);
}
示例14: __construct
/**
* Constructs a new validator, initializing the minimum valid value.
*
* @param \Zikula_ServiceManager $serviceManager The current service manager instance.
* @param integer $value The minimum valid value for the field data.
* @param string $errorMessage The error message to return if the field data is not valid.
*
* @throws \InvalidArgumentException If the minimum value specified is not an integer.
*/
public function __construct(\Zikula_ServiceManager $serviceManager, $value, $errorMessage = null)
{
parent::__construct($serviceManager, $errorMessage);
if (!isset($value) || !is_int($value) || $value < 0) {
throw new \InvalidArgumentException($this->__('An invalid integer value was received.'));
}
$this->value = $value;
}
示例15: __construct
/**
* Do our own constructor so we can set the maxfilesize and check the ruleSet
* @param \Foundation\Form\Element $e the element we are validating
* @param integer $sizeInBytes
*/
public function __construct(\Foundation\Form\Element $element, $sizeInBytes)
{
if (!($integer = \intval($sizeInBytes))) {
throw new \Foundation\Exception("The ruleset for MaximumFileSize must be an integer. Value: '{$sizeInBytes}'");
}
parent::__construct($element, $integer);
$this->e->setMaxSize($this->ruleSet);
}