From 1839726dc03ab21ed3210b92ef13c35773210725 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Tue, 14 Apr 2020 11:36:55 -0400 Subject: [PATCH] - Fixed string's length based on annotation (if set) --- src/EntityTrait.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/EntityTrait.php b/src/EntityTrait.php index 148514f..7623235 100644 --- a/src/EntityTrait.php +++ b/src/EntityTrait.php @@ -159,6 +159,15 @@ trait EntityTrait { $this->{$field['name']} = substr($value, 0, 1) === "a" ? unserialize($value) : json_decode($value, true); } elseif ( EntityField::isScalarType($field['type']) ) { + + if ( $field['type'] === 'string' ) { + $annotation = $entityResolver->searchFieldAnnotation($field['name'], new Field() ); + + if ( $annotation->length ?? null ) { + $value = substr($value, 0, $annotation->length); + } + } + $this->{$field['name']} = $value; } elseif ( ! $field['builtin'] ) {