Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/json-renderer-merge-unnamed-children' of https:/…
Browse files Browse the repository at this point in the history
…/github.com/mpinkston/zf2 into hotfix/view-jsonrenderer-child-merge
  • Loading branch information
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/Model/JsonModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
*/
class JsonModel extends ViewModel
{
/**
* JSON probably won't need to be captured into a
* a parent container by default.
*
* @var string
*/
protected $captureTo = null;

/**
* JSON is usually terminal
*
Expand All @@ -51,6 +59,6 @@ public function serialize()
if ($variables instanceof Traversable) {
$variables = ArrayUtils::iteratorToArray($variables);
}
return json_encode($variables);
return Json::encode($variables);
}
}
4 changes: 4 additions & 0 deletions src/Renderer/JsonRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ public function canRenderTrees()
protected function recurseModel(Model $model)
{
$values = $model->getVariables();
if ($values instanceof Traversable) {
$values = ArrayUtils::iteratorToArray($values);
}

if (!$model->hasChildren()) {
return $values;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Variables.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __construct(array $variables = array(), array $options = array()
{
parent::__construct(
$variables,
ArrayObject::STD_PROP_LIST|ArrayObject::ARRAY_AS_PROPS,
ArrayObject::ARRAY_AS_PROPS,
'ArrayIterator'
);

Expand Down

0 comments on commit 447525a

Please sign in to comment.