\LazyJsonMapper\PropertyValueConverter

Automatic variable type converter and validator.

Summary

Methods
Properties
Constants
convert()
No public properties found
CONVERT_FROM_INTERNAL
CONVERT_TO_INTERNAL
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Constants

CONVERT_FROM_INTERNAL

CONVERT_FROM_INTERNAL

Convert an outgoing internal value for external use.

CONVERT_TO_INTERNAL

CONVERT_TO_INTERNAL

Convert an incoming external value to internal storage.

Methods

convert()

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:

Incoming (CONVERT_TO_INTERNAL):

  • Processes a new value for an object property to ensure correctness.

  • Verifies that the new value matches the correct type for the property and does type-casting of built-in PHP types and verification of object types.

Outgoing (CONVERT_FROM_INTERNAL):

  • Converts an object property to its assigned class or built-in PHP type.

  • Performs automatic casting of basic PHP types, along with non-recursive lazy-creation of class objects (the first time it encounters any unconverted objects at the currently requested property's depth). The non-recursion is intentional, for performance and memory purposes. Objects within the created objects will remain as basic JSON-array data until you actually access them, at which point they're lazy-created too.

Parameters

integer $direction

One of the CONVERT_* constants.

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 $propDef->arrayDepth.

string $propName

The name of the property. For exception messages.

\LazyJsonMapper\Property\PropertyDefinition $propDef

An object describing the property.

Throws

\LazyJsonMapper\Exception\LazyJsonMapperException

If the value can't be turned into its assigned class or built-in PHP type.