/** * Provided a model class name and an attribute name, get the min length for that attribute. * @param string $modelClassName * @param string $attributeName */ protected function resolveMinLength($modelClassName, $attributeName) { assert('is_string($modelClassName)'); assert('is_string($attributeName)'); $model = new $modelClassName(false); return StringValidatorHelper::getMinLengthByModelAndAttributeName($model, $attributeName); }
/** * Given a value that is a full name, split the full name into the first and last name parts. Validate that * the first and last name are not too large for their attributes. If they are too large or the full name * does not valid properly, then 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('$attributeName == null'); assert('$mappingRuleData == null'); if ($value == null) { return $value; } @(list($firstName, $lastName) = explode(' ', trim($value))); if ($lastName == null) { $lastName = $firstName; $firstName = null; } if ($lastName == null) { throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', 'The full name must contain a last name, which is required.')); } $model = new $modelClassName(false); $firstNameMaxLength = StringValidatorHelper::getMaxLengthByModelAndAttributeName($model, 'firstName'); $lastNameMaxLength = StringValidatorHelper::getMaxLengthByModelAndAttributeName($model, 'lastName'); $lastNameMinLength = StringValidatorHelper::getMinLengthByModelAndAttributeName($model, 'lastName'); if (strlen($lastName) > $lastNameMaxLength) { throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', 'Last name specified is too long.')); } if (strlen($lastName) < $lastNameMinLength) { throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', 'Last name specified is too short.')); } if ($firstName != null && strlen($firstName) > $firstNameMaxLength) { throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', 'First name specified is too long.')); } return $value; }
public function __construct(RedBeanModel $model = null, $attributeName = null) { parent::__construct($model, $attributeName); if ($model !== null) { $maxLength = StringValidatorHelper::getMaxLengthByModelAndAttributeName($model, $attributeName); if ($maxLength !== null) { $this->maxLength = $maxLength; } } }
/** * Override to ensure the $attributeName is a single value and also to resolve the max name length. * @param string $modelClassName * @param string $attributeName */ public function __construct($modelClassName, $attributeName) { parent::__construct($modelClassName, $attributeName); assert('is_string($attributeName)'); $attributeModelClassName = $this->attributeModelClassName; $model = new $attributeModelClassName(false); assert('$model->isAttribute("name")'); $this->maxNameLength = StringValidatorHelper::getMaxLengthByModelAndAttributeName($model, 'name'); $this->messageCountData[static::NEW_NAME_TO0_LONG] = 0; }
public function __construct($modelClassName, $attributeName) { parent::__construct($modelClassName, $attributeName); assert('$attributeName == null'); $this->messageCountData[static::FULL_NAME_TOO_LONG] = 0; $this->messageCountData[static::FULL_NAME_TOO_SHORT] = 0; $model = new $modelClassName(false); $this->firstNameMaxLength = StringValidatorHelper::getMaxLengthByModelAndAttributeName($model, 'firstName'); $this->lastNameMaxLength = StringValidatorHelper::getMaxLengthByModelAndAttributeName($model, 'lastName'); $this->lastNameMinLength = StringValidatorHelper::getMinLengthByModelAndAttributeName($model, 'lastName'); }
/** * Given a value, resolve that the value not too large for the attribute based on the attribute's type. If * the value is too large, then it is truncated. * @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'); $model = new $modelClassName(false); $minLength = StringValidatorHelper::getMinLengthByModelAndAttributeName($model, $attributeName); if ($value == null) { return $value; } if (strlen($value) >= $minLength) { return $value; } throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', 'Value is too short.')); }
/** * Given a value, resolve that the value not too large for the attribute based on the attribute's type. If * the value is too large, then it is truncated. * @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'); $model = new $modelClassName(false); $maxLength = StringValidatorHelper::getMaxLengthByModelAndAttributeName($model, $attributeName); if ($value == null) { return $value; } if (strlen($value) < $maxLength) { return $value; } return substr($value, 0, $maxLength); }
protected function init() { parent::init(); $modelClassName = $this->modelClassName; $model = new $modelClassName(false); $this->attributeModelClassName = $this->resolveAttributeModelClassName($model, $this->attributeName); $attributeModelClassName = $this->attributeModelClassName; $model = new $attributeModelClassName(false); if ($this->mappingRuleData["type"] == RelatedModelValueTypeMappingRuleForm::ZURMO_MODEL_NAME && !$model->isAttribute("name")) { throw new NotSupportedException(); } $this->maxNameLength = StringValidatorHelper::getMaxLengthByModelAndAttributeName($model, 'name'); }
/** * @return int|null minimum length */ protected function getMaximumLength() { $modelClassName = $this->modelClassName; $model = new $modelClassName(false); return StringValidatorHelper::getMaxLengthByModelAndAttributeName($model, $this->attributeName); }