public function __construct(RedBeanModel $model = null, $attributeName = null) { assert('$attributeName === null || is_string($attributeName)'); assert('$model === null || $model->isAttribute($attributeName)'); if ($model !== null) { $this->attributeName = $attributeName; $this->attributeLabels = $model->getAttributeLabelsForAllActiveLanguagesByAttributeName($attributeName); $this->attributePropertyToDesignerFormAdapter = new AttributePropertyToDesignerFormAdapter(); $validators = $model->getValidators($attributeName); foreach ($validators as $validator) { if ($validator instanceof CDefaultValueValidator) { $this->defaultValue = $validator->value; } elseif ($validator instanceof CRequiredValidator) { $this->isRequired = true; $modelAttributesAdapter = new ModelAttributesAdapter($model); if ($modelAttributesAdapter->isStandardAttribute($attributeName) && $modelAttributesAdapter->isStandardAttributeRequiredByDefault($attributeName)) { $this->attributePropertyToDesignerFormAdapter->setUpdateRequiredFieldStatus(false); } } } if ($model instanceof Item && $attributeName != null) { $this->isAudited = $model->isAttributeAudited($attributeName); } } }
/** * Given a model and attributeName, get the min length for that attribute as defined by the metadata rules. * @param object $model RedBeanModel * @param string $attributeName */ public static function getMinLengthByModelAndAttributeName(RedBeanModel $model, $attributeName) { assert('is_string($attributeName)'); $validators = $model->getValidators($attributeName); $minLength = null; foreach ($validators as $validator) { if ($validator instanceof CStringValidator) { if ($validator->min !== null) { $minLength = $validator->min; break; } } } return $minLength; }