Small improvements

This commit is contained in:
Alexandre Gomes Gaigalas 2010-12-07 11:37:07 -02:00
parent b3cc2285fc
commit 896fe166c8
10 changed files with 52 additions and 18 deletions

View file

@ -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)',
);
}

View file

@ -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();
}
}

View 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;
}
}

View file

@ -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',
);
}

View file

@ -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',
);
}

View file

@ -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',
);
}

View file

@ -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;
}

View file

@ -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)

View file

@ -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);
}
}

View file

@ -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)));
}
}