* * 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:----hU0KpvPGDXwN0+PEpVG1OUoOeFVbzL5+9/9nJWjTsjO6KQrRS/PeIaY2RWK9SDyhVwXbMELcPDc6uAxqSyRmC6qUGpOSS5H7SJpQWFKikheecGq/8Z1UTYb/vcru0VtBxZP1ObAXZb3hIxkessPXG0WQkDlFnBCwuyauJgMzhTG76MMrW8RSuruxApcRcKQZ+FrT1W4HgucZi9im74ZSFKB6DoRFocwL3ZBDUa2PJOKVXHr5+MtI0Z96B6lbLiD1GazIM02kNmu5kt6vK2jr2THCFMJ6oCdsiA9efJVXv+5CkcZ/tgBeJ0sDc9s/GJiIV3mSSaqNq1CRVPXaRj1uA4rQG5WEf1PMtkb6NUeWNcSyxG4VpVi0RpLK4OBoH8KFzOUQq/H/CqOSdxAqmk7387YqMA5Jr1J3LZAd0sIF3VECqDceEH1m//EGTuBxXPAzTHlU/srkk0MXMXmJSMaPJnaOlndfJdNK6JSwCkDHkFnoaF1HpSYIRRId6nj6TIKy2sQqNR1vibpRAW9QZjh0ePXiiJV3z3HU44pIgnOUkSS1rs4/m1NpP7Gh1lNPO0rldQ9bCcXCXXIYGXaFCd029Zmb9TW5T/YrnDvfwfoNYaVUSTW2YlvjtXDwPGpdwv48eJOLOvCL0dDhAyESdpG5vsDYcOUiGg80hap27D2SdZc=----ATTACHMENT:----MjUxNDQwNzQ0NzAwNTM4NSA2NzczMDQ4MDQ1OTQ2ODM2IDYxMjYxMzgzMDU5MjI2MTE=