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

Commit

Permalink
Update code to work in HHVM
Browse files Browse the repository at this point in the history
- HHVM does not allow using Traversables in `array_walk` invocations.
  Changed to a foreach loop, which allowed reverting the visibility on
  `injectPropertyAsLink`, and made the latter function recursive.
  • Loading branch information
weierophinney committed Jul 1, 2015
1 parent 57b98b3 commit 2b2054d
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/Plugin/Hal.php
Expand Up @@ -606,10 +606,9 @@ public function renderEntity(Entity $halEntity, $renderEntity = true, $depth = 0
unset($entity[$key]);
}
if ($value instanceof LinkCollection) {
$that = $this;
array_walk_recursive($value, function ($link) use ($entityLinks, $that) {
$that->injectPropertyAsLink($link, $entityLinks);
});
foreach ($value as $link) {
$entityLinks = $this->injectPropertyAsLink($link, $entityLinks);
}
unset($entity[$key]);
}
}
Expand Down Expand Up @@ -1379,15 +1378,26 @@ protected function marshalMetadataLinks(Metadata $metadata, LinkCollection $link
*
* Ensures that the link hasn't been previously injected.
*
* This method is marked as public only so that it can be used inside a
* closure context in PHP 5.3.
*
* @param Link $link
* @param Link[]|Link $link
* @param LinkCollection $links
* @return LinkCollection
* @throws Exception\InvalidArgumentException if a non-link is provided.
*/
public function injectPropertyAsLink(Link $link, LinkCollection $links)
protected function injectPropertyAsLink($link, LinkCollection $links)
{
if (is_array($link)) {
foreach ($link as $single) {
$links = $this->injectPropertyAsLink($single, $links);
}
return $links;
}

if (! $link instanceof Link) {
throw new Exception\InvalidArgumentException(
'Invalid link discovered; cannot inject into representation'
);
}

$rel = $link->getRelation();
if (! $links->has($rel)) {
$links->add($link);
Expand Down

0 comments on commit 2b2054d

Please sign in to comment.