diff --git a/src/Manager.php b/src/Manager.php index 2d565aaf..b3eb9491 100644 --- a/src/Manager.php +++ b/src/Manager.php @@ -164,6 +164,7 @@ public function parseIncludes($includes) { // Wipe these before we go again $this->requestedIncludes = $this->includeParams = []; + $subRelations = ''; if (is_string($includes)) { $includes = explode(',', $includes); @@ -177,6 +178,7 @@ public function parseIncludes($includes) foreach ($includes as $include) { list($includeName, $allModifiersStr) = array_pad(explode(':', $include, 2), 2, null); + list($allModifiersStr, $subRelations) = array_pad(explode('.', $allModifiersStr, 2), 2, null); // Trim it down to a cool level of recursion $includeName = $this->trimToAcceptableRecursionLevel($includeName); @@ -212,6 +214,10 @@ public function parseIncludes($includes) } $this->includeParams[$includeName] = $modifierArr; + + if ($subRelations) { + $this->requestedIncludes[] = $this->trimToAcceptableRecursionLevel($includeName . '.' . $subRelations); + } } // This should be optional and public someday, but without it includes would never show up diff --git a/test/ManagerTest.php b/test/ManagerTest.php index fbfbd174..475c52af 100755 --- a/test/ManagerTest.php +++ b/test/ManagerTest.php @@ -56,6 +56,10 @@ public function testParseIncludes() $manager->parseIncludes(['foo', 'foo', 'bar']); $this->assertSame(['foo', 'bar'], $manager->getRequestedIncludes()); + $manager->parseIncludes(['foo.bar', 'foo:limit(10|1).bar']); + $this->assertSame(['foo', 'foo.bar'], $manager->getRequestedIncludes()); + $this->assertSame(['10', '1'], $manager->getIncludeParams('foo')->get('limit')); + // Do requests for `baz.bart` also request `baz`? $manager->parseIncludes(['foo.bar']); $this->assertSame(['foo', 'foo.bar'], $manager->getRequestedIncludes()); @@ -74,6 +78,17 @@ public function testParseIncludes() $this->assertSame([''], $params['anotherparam']); $this->assertNull($params['totallymadeup']); + + // Relation with params and sub relation + $manager->parseIncludes('foo:limit(5|1):order(name).bar,baz'); + + $params = $manager->getIncludeParams('foo'); + + $this->assertInstanceOf('League\Fractal\ParamBag', $params); + + $this->assertSame(['5', '1'], $params['limit']); + $this->assertSame(['name'], $params['order']); + $this->assertSame(['foo', 'foo.bar', 'baz'], $manager->getRequestedIncludes()); } public function testParseExcludeSelfie() @@ -151,6 +166,24 @@ public function testRecursionLimiting() $manager->getRequestedIncludes() ); + $manager->parseIncludes('a:limit(5|1).b.c.d.e.f.g.h.i.j.NEVER'); + + $this->assertSame( + [ + 'a', + 'a.b', + 'a.b.c', + 'a.b.c.d', + 'a.b.c.d.e', + 'a.b.c.d.e.f', + 'a.b.c.d.e.f.g', + 'a.b.c.d.e.f.g.h', + 'a.b.c.d.e.f.g.h.i', + 'a.b.c.d.e.f.g.h.i.j', + ], + $manager->getRequestedIncludes() + ); + // Try setting to 3 and see what happens $manager->setRecursionLimit(3); $manager->parseIncludes('a.b.c.NEVER'); @@ -163,6 +196,17 @@ public function testRecursionLimiting() ], $manager->getRequestedIncludes() ); + + $manager->parseIncludes('a:limit(5|1).b.c.NEVER'); + + $this->assertSame( + [ + 'a', + 'a.b', + 'a.b.c', + ], + $manager->getRequestedIncludes() + ); } public function testCreateDataWithCallback()