调整logicTrait 基类

This commit is contained in:
liaofei 2019-11-19 16:19:25 +08:00
parent 2e6ed45f60
commit a9dc22ddc0

View File

@ -151,18 +151,23 @@ trait LogicTrait
$attribute = lcfirst(str_replace('set', '', $method)); $attribute = lcfirst(str_replace('set', '', $method));
if (property_exists($this, $attribute) && in_array($attribute, $propsRuleKeys)) { if (property_exists($this, $attribute) && in_array($attribute, $propsRuleKeys)) {
$propsRuleValeu = $this->propsRule[$attribute]; $propsRuleValeu = $this->propsRule[$attribute];
$type = $propsRuleValeu[1] ?? 'string'; $valeu = null;
$callable = $propsRuleValeu[2] ?? null; if (is_array($propsRuleValeu)) {
if ($type == 'callable' && $callable) { $type = $propsRuleValeu[1] ?? 'string';
$callable = $propsRuleValeu[2]; $callable = $propsRuleValeu[2] ?? null;
if (method_exists($this, $callable)) if ($type == 'callable' && $callable) {
$ages[0] = $this->{$callable}($ages[0], $ages[1] ?? ''); $callable = $propsRuleValeu[2];
if (method_exists($this, $callable))
$ages[0] = $this->{$callable}($ages[0], $ages[1] ?? '');
} else if ($type) { } else if ($type) {
$ages[0] = $this->toType($ages[0], $type) ?? null; $ages[0] = $this->toType($ages[0], $type) ?? null;
}
} else {
$valeu = $propsRuleValeu;
} }
$this->{$attribute} = $ages[0]; $this->{$attribute} = $ages[0] ?? $valeu;
return $this; return $this;
} }
} else if (in_array($method, $keys)) { } else if (in_array($method, $keys)) {