Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,9 @@ public function parseIncludes($includes): self
// Trim it down to a cool level of recursion
$includeName = $this->trimToAcceptableRecursionLevel($includeName);

if (in_array($includeName, $this->requestedIncludes)) {
continue;
if (!in_array($includeName, $this->requestedIncludes)) {
$this->requestedIncludes[] = $includeName;
}
$this->requestedIncludes[] = $includeName;

// No Params? Bored
if ($allModifiersStr === null) {
Expand All @@ -164,10 +163,16 @@ public function parseIncludes($includes): self
$modifierArr[$modifierName] = explode($this->paramDelimiter, $modifierParamStr);
}

$this->includeParams[$includeName] = $modifierArr;
if (!isset($this->includeParams[$includeName])) {
$this->includeParams[$includeName] = $modifierArr;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you consider collecting all values into a list of modifierArr?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but I'm not sure if this is the best design choice. I think it would have to be discussed with upstream. I wanted to limit changes to a bugfix and keep backward compatibility.

}

if ($subRelations) {
$this->requestedIncludes[] = $this->trimToAcceptableRecursionLevel($includeName . '.' . $subRelations);
$subRelationsIncludeName = $this->trimToAcceptableRecursionLevel($includeName . '.' . $subRelations);

if (!in_array($subRelationsIncludeName, $this->requestedIncludes)) {
$this->requestedIncludes[] = $subRelationsIncludeName;
}
}
}

Expand Down
14 changes: 14 additions & 0 deletions test/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ public function testParseIncludes()
$this->assertSame(['5', '1'], $params['limit']);
$this->assertSame(['name'], $params['order']);
$this->assertSame(['foo', 'foo.bar', 'baz'], $manager->getRequestedIncludes());

// The first relation modifier wins
$manager->parseIncludes('foo:modifier(1).bar,foo:modifier(2).baz');

$params = $manager->getIncludeParams('foo');

$this->assertInstanceOf('League\Fractal\ParamBag', $params);

$this->assertSame(['1'], $params['modifier']);

// Two sub relations with parent using modifier
$manager->parseIncludes('foo:modifier.bar,foo:modifier.baz');

$this->assertSame(['foo', 'foo.bar', 'foo.baz'], $manager->getRequestedIncludes());
}

public function testParseExcludeSelfie()
Expand Down