diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 5a47253..dcb28f9 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -6,6 +6,9 @@ + + + @@ -311,9 +314,9 @@ - - - + + + @@ -333,18 +336,18 @@ - + + - diff --git a/src/Pecee/SimpleRouter/Route/RouteGroup.php b/src/Pecee/SimpleRouter/Route/RouteGroup.php index 1c4cc33..e3fc8ac 100644 --- a/src/Pecee/SimpleRouter/Route/RouteGroup.php +++ b/src/Pecee/SimpleRouter/Route/RouteGroup.php @@ -52,8 +52,16 @@ class RouteGroup extends Route implements IGroupRoute return false; } + // Parse parameter + + $prefix = $this->prefix; + + foreach($this->getParameters() as $parameter => $value) { + $prefix = str_ireplace('{' . $parameter . '}', $value, $prefix); + } + /* Skip if prefix doesn't match */ - if ($this->prefix !== null && stripos($url, $this->prefix) === false) { + if ($this->prefix !== null && stripos($url, $prefix) === false) { return false; } diff --git a/tests/Pecee/SimpleRouter/RouterPartialGroupTest.php b/tests/Pecee/SimpleRouter/RouterPartialGroupTest.php index 21c9fe2..40e288a 100644 --- a/tests/Pecee/SimpleRouter/RouterPartialGroupTest.php +++ b/tests/Pecee/SimpleRouter/RouterPartialGroupTest.php @@ -25,4 +25,49 @@ class RouterPartialGroupTest extends \PHPUnit\Framework\TestCase $this->assertEquals('param2', $result2); } + /** + * Fixed issue with partial routes not loading child groups. + * Reported in issue: #456 + */ + public function testPartialGroupWithGroup() { + + $lang = null; + + $route1 = '/lang/da/test/'; + $route2 = '/lang/da/auth'; + $route3 = '/lang/da/auth/test'; + + TestRouter::partialGroup( + '/lang/{test}/', + function ($lang = 'en') use($route1, $route2, $route3) { + + TestRouter::get('/test/', function () use($route1) { + return $route1; + }); + + TestRouter::group(['prefix' => '/auth/'], function () use($route2, $route3) { + + TestRouter::get('/', function() use($route2) { + return $route2; + }); + + TestRouter::get('/test', function () use($route3){ + return $route3; + }); + + }); + + } + ); + + $test1 = TestRouter::debugOutput('/lang/da/test', 'get', false); + $test2 = TestRouter::debugOutput('/lang/da/auth', 'get', false); + $test3 = TestRouter::debugOutput('/lang/da/auth/test', 'get', false); + + $this->assertEquals($test1, $route1); + $this->assertEquals($test2, $route2); + $this->assertEquals($test3, $route3); + + } + } \ No newline at end of file diff --git a/tests/TestRouter.php b/tests/TestRouter.php index a6a5321..c6acbca 100644 --- a/tests/TestRouter.php +++ b/tests/TestRouter.php @@ -13,7 +13,7 @@ class TestRouter extends \Pecee\SimpleRouter\SimpleRouter static::start(); } - public static function debug($testUrl, $testMethod = 'get') + public static function debug($testUrl, $testMethod = 'get', bool $reset = true) { try { static::debugNoReset($testUrl, $testMethod); @@ -22,17 +22,19 @@ class TestRouter extends \Pecee\SimpleRouter\SimpleRouter throw $e; } - static::router()->reset(); + if($reset === true) { + static::router()->reset(); + } } - public static function debugOutput($testUrl, $testMethod = 'get') + public static function debugOutput($testUrl, $testMethod = 'get', bool $reset = true) { $response = null; // Route request ob_start(); - static::debug($testUrl, $testMethod); + static::debug($testUrl, $testMethod, $reset); $response = ob_get_contents(); ob_end_clean();