Skip to content

Commit

Permalink
Merge pull request #34 from GSokol/nilportugues
Browse files Browse the repository at this point in the history
Avoid "Uncaught Warning: Invalid argument supplied for foreach()" warning
  • Loading branch information
nilportugues authored Apr 4, 2017
2 parents ed9cd7a + e936512 commit d1a9e4d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Serializer/JsonApiSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ private function mapUrls(JsonApiTransformer $transformer, Router $router)
$mappingProperty = $mappingClass->getProperty('otherUrls');
$mappingProperty->setAccessible(true);
$otherUrls = $mappingProperty->getValue($mapping);
if (empty($otherUrls)) {
$otherUrls = [];
}
foreach ($otherUrls as &$url) {
$url = $this->getUrlPattern($router, $url, $baseUrl);
}
Expand All @@ -67,6 +70,9 @@ private function mapUrls(JsonApiTransformer $transformer, Router $router)
$mappingProperty = $mappingClass->getProperty('relationshipSelfUrl');
$mappingProperty->setAccessible(true);
$relationshipSelfUrl = $mappingProperty->getValue($mapping);
if (empty($relationshipSelfUrl)) {
$relationshipSelfUrl = [];
}
foreach ($relationshipSelfUrl as &$urlMember) {
foreach ($urlMember as &$url) {
$url = $this->getUrlPattern($router, $url, $baseUrl);
Expand Down

0 comments on commit d1a9e4d

Please sign in to comment.