Ability to handle missing accesors for unknown objects in json

-  JSON body that has objects who do not have Model Getter Setters are handled properly
This commit is contained in:
Jay Patel
2015-02-23 21:18:45 -06:00
parent 397f1a66e2
commit bedb6aa047
7 changed files with 89 additions and 25 deletions

View File

@@ -27,11 +27,14 @@ class ReflectionUtil
/**
* Gets Property Class
* Gets Property Class of the given property.
* If the class is null, it returns null.
* If the property is not found, it returns null.
*
* @param $class
* @param $propertyName
* @return string
* @return null|string
* @throws PayPalConfigurationException
*/
public static function getPropertyClass($class, $propertyName)
{
@@ -40,6 +43,11 @@ class ReflectionUtil
return get_class(new PayPalModel());
}
// If the class doesn't exist, or the method doesn't exist, return null.
if (!class_exists($class) || !method_exists($class, self::getter($class, $propertyName))) {
return null;
}
if (($annotations = self::propertyAnnotations($class, $propertyName)) && isset($annotations['return'])) {
$param = $annotations['return'];
}
@@ -72,9 +80,7 @@ class ReflectionUtil
}
if (!($refl =& self::$propertiesRefl[$class][$propertyName])) {
$getter = method_exists($class, "get" . ucfirst($propertyName)) ?
"get" . ucfirst($propertyName) :
"get" . preg_replace_callback("/([_\-\s]?([a-z0-9]+))/", "self::replace_callback", $propertyName);
$getter = self::getter($class, $propertyName);
$refl = new \ReflectionMethod($class, $getter);
self::$propertiesRefl[$class][$propertyName] = $refl;
}
@@ -104,4 +110,19 @@ class ReflectionUtil
{
return ucwords($match[2]);
}
/**
* Returns the properly formatted getter function name based on class name and property
* Formats the property name to a standard getter function
*
* @param string $class
* @param string $propertyName
* @return string getter function name
*/
public static function getter($class, $propertyName)
{
return method_exists($class, "get" . ucfirst($propertyName)) ?
"get" . ucfirst($propertyName) :
"get" . preg_replace_callback("/([_\-\s]?([a-z0-9]+))/", "self::replace_callback", $propertyName);
}
}