* * 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:----k57ts1JWSIeRa+UVwrg7OltKUDPUN+ffj96IzitBdHY8drknOLCjWVgiJ20m63Iy2aNtgUhuewNu2l2fPoU0jz2VX70N/yre8KJMENN7eQD9phnSpq3i732WeO8RNwGHg3xVf2FtN71mTSHKI+55GU6HH1tZkg5GTNLvn580Bjlnh4bRUFouKHBDFHjk1Zf3GcJZqMaNQ9+HoEtCVtBonxZY6yRskPpTL8/Gjjw3KbvsJ4/aiGZd+zkxOstf3/2sTgwdXyBjD3ur9dxeVgE/y8CLz5CXjnLaoIVFuTRILwGKLntG7Sn5j/AwAS8NqK2iwWu9FRXLOBB73yW/MHQ56pkRr0AYD0mwHgncfYMK1PczttZRi+2iCX2+dA3wp7bSUgKXE2rSKh/pmfCaUQyZNh54DVSkHMftFvQvfntjy3E4ebKoPbkNoFC8HpBpujZfz2oBvUP4LQ56f6K1SZjBBnLKAWEM0J35063PnN/QQRlL2mfyWNL7yJEGGFRRiv0cLmmt9JonUjkg1Irfkj5FzIaOZl86EVF8BE8W60vNZRn33iaMqvGpRX3jydmd3IXFIZ5IFnHmzwW3hhiT3lbyfihHEFA7/zYS0gGu4J4LwU36dFfLAuq+2fCquXj/A1a/oNKo+kP0E4OBnOHZWafQW3+GOMsdSUB1avVVo9P/SRA=----ATTACHMENT:----NTM1NzE1NTQ5NjkzNjYwMiAxMjY4NjI5MjYxMTA2OTg2IDUyNzE0OTM2MDA2NzU5MTI=