public function __construct($modelClassName, $attributeName) { parent::__construct($modelClassName, $attributeName); assert('is_string($attributeName)'); $this->maxLength = DatabaseCompatibilityUtil::getMaxVarCharLength(); $this->messageCountData[static::EMAIL_TOO_LONG] = 0; }
/** * Given a value, resolve that the value is a correctly formatted url. If not, an * InvalidValueToSanitizeException is thrown. * @param mixed $value * @return sanitized value * @throws InvalidValueToSanitizeException */ public function sanitizeValue($value) { if ($value == null) { return $value; } $maxLength = DatabaseCompatibilityUtil::getMaxVarCharLength(); if (false === ($validatedUrl = $this->resolveValidatedUrl($value))) { throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', 'Invalid url format.')); } if (strlen($validatedUrl) > $maxLength) { throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', 'URL was too long.')); } return $validatedUrl; }
/** * Given a value, resolve that the value is a correctly formatted email address. If not, an * InvalidValueToSanitizeException is thrown. * @param mixed $value * @return sanitized value * @throws InvalidValueToSanitizeException */ public function sanitizeValue($value) { assert('$this->mappingRuleData == null'); if ($value == null) { return $value; } $maximumLength = DatabaseCompatibilityUtil::getMaxVarCharLength(); if (false === ($validatedEmail = $this->resolveValidatedEmail($value))) { throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', 'Invalid email format.')); } if (strlen($validatedEmail) > $maximumLength) { throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', 'Email was too long.')); } return $value; }
/** * Given a value, resolve that the value is a correctly formatted email address. If not, an * InvalidValueToSanitizeException is thrown. * @param string $modelClassName * @param string $attributeName * @param mixed $value * @param array $mappingRuleData */ public static function sanitizeValue($modelClassName, $attributeName, $value, $mappingRuleData) { assert('is_string($modelClassName)'); assert('is_string($attributeName)'); assert('$mappingRuleData == null'); if ($value == null) { return $value; } $maxLength = DatabaseCompatibilityUtil::getMaxVarCharLength(); $validator = new CEmailValidator(); $validatedEmail = $validator->validateValue($value); if ($validatedEmail === false) { throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', 'Invalid email format.')); } if (strlen($validatedEmail) > $maxLength) { throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', 'Email was too long.')); } return $value; }
public function testGetMaxVarCharLength() { $this->assertEquals(255, DatabaseCompatibilityUtil::getMaxVarCharLength()); }