Added TJsonDecode.php - defines new TJsonDecode trait to facilitate deserialising classes from JSON. The public API consists of a single static method: add_json_decode_field($name, $callback) - attaches the function given in $callback as a 'handler' for deserialising the JSON property in $name (currently only if $name exists in the JSON, failing silently otherwise). Additionally to use the trait the using class needs to use one method from the 'protected api': decode_json_fields($json) - accepts a literal JSON string, a path to a JSON file or an already decoded object and passes all relevant properties to the handlers added with add_json_decode_field() decode_json_fields() may (currently) throw an InvalidArgumentException if passed anything other than an object or string, or an Exception if passed a string/path which it cannot decode (due to errors logged by json_decode())
Added TJsonDecode.php - defines new TJsonDecode trait to facilitate deserialising classes from JSON.
The public API consists of a single static method: add_json_decode_field($name, $callback) - attaches the function given in $callback as a 'handler' for deserialising the JSON property in $name (currently only if $name exists in the JSON, failing silently otherwise).
Additionally to use the trait the using class needs to use one method from the 'protected api': decode_json_fields($json) - accepts a literal JSON string, a path to a JSON file or an already decoded object and passes all relevant properties to the handlers added with add_json_decode_field()
decode_json_fields() may (currently) throw an InvalidArgumentException if passed anything other than an object or string, or an Exception if passed a string/path which it cannot decode (due to errors logged by json_decode())

Omnikron13/php-utility-traits