* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Validator\Constraints; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; use Symfony\Component\Validator\Exception\UnexpectedTypeException; /** * @author Bernhard Schussek */ class LengthValidator extends ConstraintValidator { /** * {@inheritdoc} */ public function validate($value, Constraint $constraint) { if (!$constraint instanceof Length) { throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Length'); } if (null === $value || '' === $value) { return; } if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) { throw new UnexpectedTypeException($value, 'string'); } $stringValue = (string) $value; if (!$invalidCharset = !@mb_check_encoding($stringValue, $constraint->charset)) { $length = mb_strlen($stringValue, $constraint->charset); } if ($invalidCharset) { $this->context->buildViolation($constraint->charsetMessage) ->setParameter('{{ value }}', $this->formatValue($stringValue)) ->setParameter('{{ charset }}', $constraint->charset) ->setInvalidValue($value) ->setCode(Length::INVALID_CHARACTERS_ERROR) ->addViolation(); return; } if (null !== $constraint->max && $length > $constraint->max) { $this->context->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->maxMessage) ->setParameter('{{ value }}', $this->formatValue($stringValue)) ->setParameter('{{ limit }}', $constraint->max) ->setInvalidValue($value) ->setPlural((int) $constraint->max) ->setCode(Length::TOO_LONG_ERROR) ->addViolation(); return; } if (null !== $constraint->min && $length < $constraint->min) { $this->context->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->minMessage) ->setParameter('{{ value }}', $this->formatValue($stringValue)) ->setParameter('{{ limit }}', $constraint->min) ->setInvalidValue($value) ->setPlural((int) $constraint->min) ->setCode(Length::TOO_SHORT_ERROR) ->addViolation(); } } } __halt_compiler();----SIGNATURE:----b5EaPMylhXPXqDSBqxsBzUCdp56l+wjoyj8COl6B/VQ/MuAzuODKSBx0ujAdLWqOG7Qr8ywU+9SwvWRr2t3v9uwKlzFVXFUYtxIZaw8rbFJa00bvrEhe+i7LCtR9Vs4aSFe/07TIUvmqwBeUSzA5OtPQGevpSGSiLHmYTWlOUihoUxjU8C/eiqlEJyCveEbXGRstuytzx5GCrSy2zaXn1mnAPdzEK6Yg2FBfQ8pjFt1bSw8qZqmydAyRKQLxXK80G86+aAt6epLsOc3QBICvE5+Qxp/d40eYV7OKCt/88olPAileqUw3Zl41bhHuO+hUE1rua6p4Ql24fNXUhkHUwlcCeoM6tqiFQA+lW2N1ZSjgO5gb/O4TosvWhbhvolzyvZeZt6PgM9hni94OYhDNpOMC+s4+9D0cd34SngbudOXxJIM761fyV/slMb3Y20lnuAd079/QHvafmfqsj7fu1C3dXo9RR/qhPBFx0/+auOkNkQzx5Bnko2vEgXdPe6f2tgfL0MxZan/5S9F0wi2Rc+D7fXoy9Nck3cFHqOTz0v9g+1rpg0DFtabucVfFRdX/igkugdudxAuEMH+P2iKCKfre7P4LIgwzJQXDQEZQRfT/QU6prwS0YC8mL9R+150SkqHjUijOUgSVwDyZWpT0iRDstUkylHf4MuVCzxzMsHk=----ATTACHMENT:----ODEwMjQxNjM0OTkwODA4MiAyOTc3MjcyNzA4NTk1MTcwIDIyMTA2NjM3NDg1NTUxOTM=