Fixed Bug in PPModel when empty json string is returned

This commit is contained in:
japatel
2014-11-06 00:10:09 -06:00
parent f997f3277e
commit d5f9b1d43c
2 changed files with 23 additions and 21 deletions

View File

@@ -151,6 +151,7 @@ class PPModel
*/ */
public function fromArray($arr) public function fromArray($arr)
{ {
if (!empty($arr)) {
foreach ($arr as $k => $v) { foreach ($arr as $k => $v) {
if (is_array($v)) { if (is_array($v)) {
$clazz = PPReflectionUtil::getPropertyClass(get_class($this), $k); $clazz = PPReflectionUtil::getPropertyClass(get_class($this), $k);
@@ -176,6 +177,7 @@ class PPModel
$this->assignValue($k, $v); $this->assignValue($k, $v);
} }
} }
}
return $this; return $this;
} }

View File

@@ -158,7 +158,7 @@ class ResultPrinter
if (is_a($object, 'PayPal\Common\PPModel')) { if (is_a($object, 'PayPal\Common\PPModel')) {
/** @var $object \PayPal\Common\PPModel */ /** @var $object \PayPal\Common\PPModel */
echo '<pre class="prettyprint '. ($error ? 'error' : '') .'">' . $object->toJSON(128) . "</pre>"; echo '<pre class="prettyprint '. ($error ? 'error' : '') .'">' . $object->toJSON(128) . "</pre>";
} elseif (\PayPal\Validation\JsonValidator::validate($object, true)) { } elseif (is_string($object) && \PayPal\Validation\JsonValidator::validate($object, true)) {
echo '<pre class="prettyprint '. ($error ? 'error' : '') .'">'. str_replace('\\/', '/', json_encode(json_decode($object), 128)) . "</pre>"; echo '<pre class="prettyprint '. ($error ? 'error' : '') .'">'. str_replace('\\/', '/', json_encode(json_decode($object), 128)) . "</pre>";
} elseif (is_string($object)) { } elseif (is_string($object)) {
echo '<pre class="prettyprint '. ($error ? 'error' : '') .'">' . $object . '</pre>'; echo '<pre class="prettyprint '. ($error ? 'error' : '') .'">' . $object . '</pre>';