CONVERT_FROM_INTERNAL
CONVERT_FROM_INTERNAL
Convert an outgoing internal value for external use.
Automatic variable type converter and validator.
convert(integer $direction, mixed $value, integer $remArrayDepth, string $propName, \LazyJsonMapper\Property\PropertyDefinition $propDef)
Validate and convert an incoming or outgoing object data property.
If any value is a literal NULL
, it will be accepted as-is.
If no type-conversion is assigned to a value, then it will undergo a
check to verify that it only holds basic PHP types (int
, float
,
string
, bool
or NULL
), or arrays of those types. Also note that
untyped (mixed) values with an array-depth specifier will undergo strict
depth validation just like any other typed value.
In all cases where the input type is specified to be an array of values, all values in the array will be processed recursively to the specified array-depth and validated to conform to JSON array standards (sequential, numeric array keys). However, note that we don't ENFORCE that an array MUST be as deep as the specified depth. We'll just traverse down all the way to that depth, while verifying that everything on the way there is valid. And we then finally ensure that all values at the specified final depth are of the correct type.
Type conversion behavior depends on the data direction:
CONVERT_TO_INTERNAL
):Processes a new value for an object property to ensure correctness.
CONVERT_FROM_INTERNAL
):Converts an object property to its assigned class or built-in PHP type.
integer | $direction | One of the |
mixed | $value | The value to be converted. Will be passed as reference. |
integer | $remArrayDepth | Remaining array-depth until we
reach the typed values. Should
be initialized to the value of
|
string | $propName | The name of the property. For exception messages. |
\LazyJsonMapper\Property\PropertyDefinition | $propDef | An object describing the property. |
If the value can't be turned into its assigned class or built-in PHP type.