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,29 +151,31 @@ class PPModel
*/ */
public function fromArray($arr) public function fromArray($arr)
{ {
foreach ($arr as $k => $v) { if (!empty($arr)) {
if (is_array($v)) { foreach ($arr as $k => $v) {
$clazz = PPReflectionUtil::getPropertyClass(get_class($this), $k); if (is_array($v)) {
if (PPArrayUtil::isAssocArray($v)) { $clazz = PPReflectionUtil::getPropertyClass(get_class($this), $k);
/** @var self $o */ if (PPArrayUtil::isAssocArray($v)) {
$o = new $clazz(); /** @var self $o */
$o->fromArray($v); $o = new $clazz();
$this->assignValue($k, $o); $o->fromArray($v);
} else { $this->assignValue($k, $o);
$arr = array(); } else {
foreach ($v as $nk => $nv) { $arr = array();
if (is_array($nv)) { foreach ($v as $nk => $nv) {
$o = new $clazz(); if (is_array($nv)) {
$o->fromArray($nv); $o = new $clazz();
$arr[$nk] = $o; $o->fromArray($nv);
} else { $arr[$nk] = $o;
$arr[$nk] = $nv; } else {
$arr[$nk] = $nv;
}
} }
$this->assignValue($k, $arr);
} }
$this->assignValue($k, $arr); } else {
$this->assignValue($k, $v);
} }
} else {
$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>';