|
| checkMissingData ($providedProperties, ReflectionClass $rc) |
|
| createInstance ( $class, $useParameter=false, $jvalue=null) |
|
| getCamelCaseName ($name) |
|
| getFullNamespace ($type, $strNs) |
|
| getMappedType ($type, $jvalue=null) |
|
| getSafeName ($name) |
|
| hasVariadicArrayType ($accessor) |
|
| inspectProperty (ReflectionClass $rc, $name) |
|
| isArrayOfType ($strType) |
|
| isFlatType ($type) |
|
| isNullable ($type) |
|
| isObjectOfSameType ($type, $value) |
|
| isSimpleType ($type) |
|
| log ($level, $message, array $context=array()) |
|
| removeNullable ($type) |
|
| removeUndefinedAttributes ($object, $providedProperties) |
|
| setProperty ( $object, $accessor, $value) |
|
| stringifyReflectionType (ReflectionType $type) |
|
Definition at line 23 of file JsonMapper.php.
◆ checkMissingData()
JsonMapper::checkMissingData |
( |
| $providedProperties, |
|
|
ReflectionClass | $rc ) |
|
protected |
Check required properties exist in json
- Parameters
-
array | $providedProperties | array with json properties |
object | $rc | Reflection class to check |
- Exceptions
-
- Returns
- void
Definition at line 387 of file JsonMapper.php.
Referenced by map().
◆ createInstance()
JsonMapper::createInstance |
( |
| $class, |
|
|
| $useParameter = false, |
|
|
| $jvalue = null ) |
|
protected |
Create a new object of the given type.
This method exists to be overwritten in child classes, so you can do dependency injection or so.
- Parameters
-
string | $class | Class name to instantiate |
boolean | $useParameter | Pass $parameter to the constructor or not |
mixed | $jvalue | Constructor parameter (the json value) |
- Returns
- object Freshly created object
Definition at line 701 of file JsonMapper.php.
Referenced by map().
◆ getCamelCaseName()
JsonMapper::getCamelCaseName |
( |
| $name | ) |
|
|
protected |
Removes - and _ and makes the next letter uppercase
- Parameters
-
- Returns
- string CamelCasedVariableName
Definition at line 636 of file JsonMapper.php.
◆ getFullNamespace()
JsonMapper::getFullNamespace |
( |
| $type, |
|
|
| $strNs ) |
|
protected |
Convert a type name to a fully namespaced type name.
- Parameters
-
string | $type | Type name (simple type or class name) |
string | $strNs | Base namespace that gets prepended to the type name |
- Returns
- string Fully-qualified type name with namespace
Definition at line 363 of file JsonMapper.php.
References isSimpleType().
Referenced by map().
◆ getMappedType()
JsonMapper::getMappedType |
( |
| $type, |
|
|
| $jvalue = null ) |
|
protected |
Get the mapped class/type name for this class. Returns the incoming classname if not mapped.
- Parameters
-
string | $type | Type name to map |
mixed | $jvalue | Constructor parameter (the json value) |
- Returns
- string The mapped type/class name
Definition at line 733 of file JsonMapper.php.
Referenced by map().
◆ getSafeName()
JsonMapper::getSafeName |
( |
| $name | ) |
|
|
protected |
Since hyphens cannot be used in variables we have to uppercase them.
Technically you may use them, but they are awkward to access.
- Parameters
-
- Returns
- string Name without hyphen
Definition at line 652 of file JsonMapper.php.
Referenced by map().
◆ hasVariadicArrayType()
JsonMapper::hasVariadicArrayType |
( |
| $accessor | ) |
|
|
protected |
Returns true if accessor is a method and has only one parameter which is variadic.
- Parameters
-
ReflectionMethod | ReflectionProperty | null | $accessor | accessor to set value |
- Returns
- bool
Definition at line 833 of file JsonMapper.php.
Referenced by map().
◆ inspectProperty()
JsonMapper::inspectProperty |
( |
ReflectionClass | $rc, |
|
|
| $name ) |
|
protected |
Try to find out if a property exists in a given class. Checks property first, falls back to setter method.
- Parameters
-
ReflectionClass | $rc | Reflection class to check |
string | $name | Property name |
- Returns
- array First value: if the property exists Second value: the accessor to use ( ReflectionMethod or ReflectionProperty, or null) Third value: type of the property Fourth value: if the property is nullable
Definition at line 508 of file JsonMapper.php.
Referenced by map().
◆ isArrayOfType()
JsonMapper::isArrayOfType |
( |
| $strType | ) |
|
|
protected |
Returns true if type is an array of elements (bracket notation)
- Parameters
-
string | $strType | type to be matched |
- Returns
- bool
Definition at line 819 of file JsonMapper.php.
Referenced by map().
◆ isFlatType()
JsonMapper::isFlatType |
( |
| $type | ) |
|
|
protected |
Checks if the given type is a type that is not nested (simple type except array, object and mixed)
- Parameters
-
string | $type | type name from gettype() |
- Returns
- boolean True if it is a non-nested PHP type
- See also
- isSimpleType()
Definition at line 802 of file JsonMapper.php.
Referenced by map().
◆ isNullable()
JsonMapper::isNullable |
( |
| $type | ) |
|
|
protected |
Checks if the given type is nullable
- Parameters
-
string | $type | type name from the phpdoc param |
- Returns
- boolean True if it is nullable
Definition at line 857 of file JsonMapper.php.
◆ isObjectOfSameType()
JsonMapper::isObjectOfSameType |
( |
| $type, |
|
|
| $value ) |
|
protected |
Checks if the object is of this type or has this type as one of its parents
- Parameters
-
string | $type | class name of type being required |
mixed | $value | Some PHP value to be tested |
- Returns
- boolean True if $object has type of $type
Definition at line 783 of file JsonMapper.php.
Referenced by map().
◆ isSimpleType()
JsonMapper::isSimpleType |
( |
| $type | ) |
|
|
protected |
Checks if the given type is a "simple type"
- Parameters
-
string | $type | type name from gettype() |
- Returns
- boolean True if it is a simple PHP type
- See also
- isFlatType()
Definition at line 764 of file JsonMapper.php.
Referenced by getFullNamespace(), and map().
◆ log()
JsonMapper::log |
( |
| $level, |
|
|
| $message, |
|
|
array | $context = array() ) |
|
protected |
Log a message to the $logger object
- Parameters
-
string | $level | Logging level |
string | $message | Text to log |
array | $context | Additional information |
- Returns
- null
Definition at line 942 of file JsonMapper.php.
Referenced by map().
◆ map()
JsonMapper::map |
( |
| $json, |
|
|
| $object ) |
Map data all data in $json into the given $object instance.
- Parameters
-
object | array | $json | JSON object structure from json_decode() |
object | class-string | $object | Object to map $json data into |
- Returns
- mixed Mapped object is returned.
- See also
- mapArray()
Definition at line 147 of file JsonMapper.php.
References checkMissingData(), createInstance(), getFullNamespace(), getMappedType(), getSafeName(), hasVariadicArrayType(), inspectProperty(), isArrayOfType(), isFlatType(), isObjectOfSameType(), isSimpleType(), log(), map(), mapArray(), removeNullable(), removeUndefinedAttributes(), and setProperty().
Referenced by map().
◆ mapArray()
JsonMapper::mapArray |
( |
| $json, |
|
|
| $array, |
|
|
| $class = null, |
|
|
| $parent_key = '' ) |
Map an array
- Parameters
-
array | $json | JSON array structure from json_decode() |
mixed | $array | Array or ArrayObject that gets filled with data from $json |
string | $class | Class name for children objects. All children will get mapped onto this type. Supports class names and simple types like "string" and nullability "string|null". Pass "null" to not convert any values |
string | $parent_key | Defines the key this array belongs to in order to aid debugging. |
- Returns
- mixed Mapped $array is returned
Definition at line 441 of file JsonMapper.php.
Referenced by map().
◆ parseAnnotations()
static JsonMapper::parseAnnotations |
( |
| $docblock | ) |
|
|
staticprotected |
Copied from PHPUnit 3.7.29, Util/Test.php
- Parameters
-
string | $docblock | Full method docblock |
- Returns
- array Array of arrays. Key is the "@"-name like "param", each value is an array of the rest of the -lines
Definition at line 914 of file JsonMapper.php.
◆ removeNullable()
JsonMapper::removeNullable |
( |
| $type | ) |
|
|
protected |
Remove the 'null' section of a type
- Parameters
-
string | $type | type name from the phpdoc param |
- Returns
- string The new type value
Definition at line 869 of file JsonMapper.php.
Referenced by map().
◆ removeUndefinedAttributes()
JsonMapper::removeUndefinedAttributes |
( |
| $object, |
|
|
| $providedProperties ) |
|
protected |
Remove attributes from object that were not passed in JSON data.
This is to avoid confusion between those that were actually passed as NULL, and those that weren't provided at all.
- Parameters
-
object | $object | Object to remove properties from |
array | $providedProperties | Array with JSON properties |
- Returns
- void
Definition at line 416 of file JsonMapper.php.
Referenced by map().
◆ setLogger()
JsonMapper::setLogger |
( |
| $logger | ) |
|
Sets a logger instance on the object
- Parameters
-
LoggerInterface | $logger | PSR-3 compatible logger object |
- Returns
- null
Definition at line 956 of file JsonMapper.php.
◆ setProperty()
JsonMapper::setProperty |
( |
| $object, |
|
|
| $accessor, |
|
|
| $value ) |
|
protected |
Set a property on a given object to a given value.
Checks if the setter or the property are public are made before calling this method.
- Parameters
-
object | $object | Object to set property on |
object | $accessor | ReflectionMethod or ReflectionProperty |
mixed | $value | Value of property |
- Returns
- void
Definition at line 673 of file JsonMapper.php.
Referenced by map().
◆ stringifyReflectionType()
JsonMapper::stringifyReflectionType |
( |
ReflectionType | $type | ) |
|
|
protected |
Get a string representation of the reflection type. Required because named, union and intersection types need to be handled.
- Parameters
-
ReflectionType | $type | Native PHP type |
- Returns
- string "foo|bar"
Definition at line 888 of file JsonMapper.php.
◆ $arInspectedClasses
JsonMapper::$arInspectedClasses = array() |
|
protected |
◆ $bEnforceMapType
JsonMapper::$bEnforceMapType = true |
◆ $bExceptionOnMissingData
JsonMapper::$bExceptionOnMissingData = false |
◆ $bExceptionOnUndefinedProperty
JsonMapper::$bExceptionOnUndefinedProperty = false |
◆ $bIgnoreVisibility
JsonMapper::$bIgnoreVisibility = false |
◆ $bRemoveUndefinedAttributes
JsonMapper::$bRemoveUndefinedAttributes = false |
◆ $bStrictNullTypes
JsonMapper::$bStrictNullTypes = true |
◆ $bStrictObjectTypeChecking
JsonMapper::$bStrictObjectTypeChecking = false |
◆ $classMap
JsonMapper::$classMap = array() |
◆ $logger
◆ $postMappingMethod
JsonMapper::$postMappingMethod = null |
◆ $postMappingMethodArguments
JsonMapper::$postMappingMethodArguments = array() |
◆ $undefinedPropertyHandler
JsonMapper::$undefinedPropertyHandler = null |
The documentation for this class was generated from the following file: