Skip to content

Commit d1a9e4d

Browse files
authored
Merge pull request #34 from GSokol/nilportugues
Avoid "Uncaught Warning: Invalid argument supplied for foreach()" warning
2 parents ed9cd7a + e936512 commit d1a9e4d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/Serializer/JsonApiSerializer.php

+6
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ private function mapUrls(JsonApiTransformer $transformer, Router $router)
5959
$mappingProperty = $mappingClass->getProperty('otherUrls');
6060
$mappingProperty->setAccessible(true);
6161
$otherUrls = $mappingProperty->getValue($mapping);
62+
if (empty($otherUrls)) {
63+
$otherUrls = [];
64+
}
6265
foreach ($otherUrls as &$url) {
6366
$url = $this->getUrlPattern($router, $url, $baseUrl);
6467
}
@@ -67,6 +70,9 @@ private function mapUrls(JsonApiTransformer $transformer, Router $router)
6770
$mappingProperty = $mappingClass->getProperty('relationshipSelfUrl');
6871
$mappingProperty->setAccessible(true);
6972
$relationshipSelfUrl = $mappingProperty->getValue($mapping);
73+
if (empty($relationshipSelfUrl)) {
74+
$relationshipSelfUrl = [];
75+
}
7076
foreach ($relationshipSelfUrl as &$urlMember) {
7177
foreach ($urlMember as &$url) {
7278
$url = $this->getUrlPattern($router, $url, $baseUrl);

0 commit comments

Comments
 (0)