mirror of
https://github.com/Respect/Validation.git
synced 2024-05-29 03:42:25 +02:00
Small improvements
This commit is contained in:
parent
b3cc2285fc
commit
896fe166c8
|
@ -6,8 +6,8 @@ class AtLeastException extends AbstractCompositeException
|
|||
{
|
||||
|
||||
public static $defaultTemplates = array(
|
||||
self::INVALID_NONE => 'None of %3$d required rules passed',
|
||||
self::INVALID_SOME => '%2$d of %3$d required rules did not passed',
|
||||
self::INVALID_NONE => 'None of %4$d rules passed (%3$d required)',
|
||||
self::INVALID_SOME => '%2$d of %4$d rules did not passed (%3$d required)',
|
||||
);
|
||||
|
||||
}
|
|
@ -4,9 +4,10 @@ namespace Respect\Validation\Exceptions;
|
|||
|
||||
class CallException extends ValidationException
|
||||
{
|
||||
const INVALID_CALL= 'Call_1';
|
||||
public static $defaultTemplates = array(
|
||||
self::INVALID_CALL => '"%s" is invalid',
|
||||
);
|
||||
|
||||
public function renderMessage()
|
||||
{
|
||||
$this->message = $this->related[0]->getMessage();
|
||||
}
|
||||
|
||||
}
|
22
library/Respect/Validation/Exceptions/EqualsException.php
Normal file
22
library/Respect/Validation/Exceptions/EqualsException.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Respect\Validation\Exceptions;
|
||||
|
||||
class EqualsException extends ValidationException
|
||||
{
|
||||
const INVALID_EQUALS= 'Equals_1';
|
||||
const INVALID_IDENTICAL= 'Equals_2';
|
||||
public static $defaultTemplates = array(
|
||||
self::INVALID_EQUALS => '"%s" is not equals "%s"',
|
||||
self::INVALID_IDENTICAL => '"%s" is not identical to "%s"',
|
||||
);
|
||||
|
||||
public function chooseTemplate($input, $equals, $identical)
|
||||
{
|
||||
if ($identical)
|
||||
return self::INVALID_IDENTICAL;
|
||||
else
|
||||
return self::INVALID_EQUALS;
|
||||
}
|
||||
|
||||
}
|
|
@ -6,7 +6,7 @@ class MaxException extends ValidationException
|
|||
{
|
||||
const INVALID_MAX= 'Max_1';
|
||||
public static $defaultTemplates = array(
|
||||
self::INVALID_MAX => '"%s" is greater than %s',
|
||||
self::INVALID_MAX => '%s is greater than %s',
|
||||
);
|
||||
|
||||
}
|
|
@ -6,7 +6,7 @@ class MinException extends ValidationException
|
|||
{
|
||||
const INVALID_MIN= 'Min_1';
|
||||
public static $defaultTemplates = array(
|
||||
self::INVALID_MIN => '"%s" is lower than %s',
|
||||
self::INVALID_MIN => '%s is lower than %s',
|
||||
);
|
||||
|
||||
}
|
|
@ -6,7 +6,7 @@ class StringLengthException extends ValidationException
|
|||
{
|
||||
const INVALID_LENGTH= 'StringLength_1';
|
||||
public static $defaultTemplates = array(
|
||||
self::INVALID_LENGTH => '"%s" is out of bounds',
|
||||
self::INVALID_LENGTH => '"%s" length out of bounds',
|
||||
);
|
||||
|
||||
}
|
|
@ -22,7 +22,7 @@ class AtLeast extends AbstractComposite
|
|||
if ($this->howMany > ($numRules - $numExceptions))
|
||||
throw $this->getException() ? : $this->createException()
|
||||
->configure(
|
||||
$input, count($exceptions), $this->howMany, $numRules
|
||||
$input, $numExceptions, $this->howMany, $numRules
|
||||
)->setRelated($exceptions);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ class Attribute extends AbstractRelated
|
|||
|
||||
protected function hasReference($input)
|
||||
{
|
||||
return property_exists($input, $this->reference);
|
||||
return @property_exists($input, $this->reference);
|
||||
}
|
||||
|
||||
protected function getReferenceValue($input)
|
||||
|
|
|
@ -19,7 +19,14 @@ class Equals extends AbstractRule
|
|||
if ($this->identical)
|
||||
return $input === $this->param;
|
||||
else
|
||||
return $inptu == $this->param;
|
||||
return $input == $this->param;
|
||||
}
|
||||
|
||||
public function assert($input)
|
||||
{
|
||||
if (!$this->validate($input))
|
||||
throw $this->getException() ? : $this->createException()
|
||||
->configure($input, $this->param, $this->identical);
|
||||
}
|
||||
|
||||
}
|
|
@ -20,12 +20,16 @@ class StringLength extends Between
|
|||
throw new ComponentException(
|
||||
sprintf('%s is not a valid numeric length', $max)
|
||||
);
|
||||
parent::__construct($min, $max);
|
||||
}
|
||||
|
||||
protected function appendRule(Validatable $validator)
|
||||
{
|
||||
parent::appendRule(new Call('strlen', $validator));
|
||||
if (!is_null($min) && !is_null($max) && $min > $max)
|
||||
throw new ComponentException(
|
||||
sprintf(
|
||||
'%s cannot be less than %s for validation', $min, $max
|
||||
)
|
||||
);
|
||||
if (!is_null($min))
|
||||
$this->addRule(new Call('strlen', new Min($min)));
|
||||
if (!is_null($max))
|
||||
$this->addRule(new Call('strlen', new Max($max)));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue