mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-07-11 17:22:17 +00:00
[BUGFIX] Fixed issue with child groups not loading when using partialGroups (issue: #456)
This commit is contained in:
Generated
+9
-6
@@ -6,7 +6,9 @@
|
|||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="a7058529-bdc4-40b4-a50d-c50564dc83f0" name="Default" comment="">
|
<list default="true" id="a7058529-bdc4-40b4-a50d-c50564dc83f0" name="Default" comment="">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/Pecee/Http/Input/InputItem.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/Pecee/Http/Input/InputItem.php" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/Pecee/SimpleRouter/Route/RouteGroup.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/Pecee/SimpleRouter/Route/RouteGroup.php" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/tests/Pecee/SimpleRouter/RouterPartialGroupTest.php" beforeDir="false" afterPath="$PROJECT_DIR$/tests/Pecee/SimpleRouter/RouterPartialGroupTest.php" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/tests/TestRouter.php" beforeDir="false" afterPath="$PROJECT_DIR$/tests/TestRouter.php" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@@ -304,9 +306,9 @@
|
|||||||
<recent name="D:\Workspace\simple-php-router\tests" />
|
<recent name="D:\Workspace\simple-php-router\tests" />
|
||||||
</key>
|
</key>
|
||||||
</component>
|
</component>
|
||||||
<component name="RunManager" selected="PHPUnit.tests">
|
<component name="RunManager" selected="PHPUnit.RouterPartialGroupTest">
|
||||||
<configuration name="EventHandlerTest" type="PHPUnitRunConfigurationType" factoryName="PHPUnit" temporary="true">
|
<configuration name="RouterPartialGroupTest" type="PHPUnitRunConfigurationType" factoryName="PHPUnit" temporary="true">
|
||||||
<TestRunner class="EventHandlerTest" file="$PROJECT_DIR$/tests/Pecee/SimpleRouter/EventHandlerTest.php" scope="Class" />
|
<TestRunner class="RouterPartialGroupTest" configuration_file="$PROJECT_DIR$/phpunit.xml" file="$PROJECT_DIR$/tests/Pecee/SimpleRouter/RouterPartialGroupTest.php" scope="Class" />
|
||||||
<method v="2" />
|
<method v="2" />
|
||||||
</configuration>
|
</configuration>
|
||||||
<configuration name="RouterRouteTest" type="PHPUnitRunConfigurationType" factoryName="PHPUnit" temporary="true">
|
<configuration name="RouterRouteTest" type="PHPUnitRunConfigurationType" factoryName="PHPUnit" temporary="true">
|
||||||
@@ -326,18 +328,18 @@
|
|||||||
</configuration>
|
</configuration>
|
||||||
<list>
|
<list>
|
||||||
<item itemvalue="PHP Script.debug.php" />
|
<item itemvalue="PHP Script.debug.php" />
|
||||||
<item itemvalue="PHPUnit.EventHandlerTest" />
|
|
||||||
<item itemvalue="PHPUnit.RouterRouteTest" />
|
<item itemvalue="PHPUnit.RouterRouteTest" />
|
||||||
<item itemvalue="PHPUnit.phpunit.xml" />
|
<item itemvalue="PHPUnit.phpunit.xml" />
|
||||||
<item itemvalue="PHPUnit.tests" />
|
<item itemvalue="PHPUnit.tests" />
|
||||||
|
<item itemvalue="PHPUnit.RouterPartialGroupTest" />
|
||||||
</list>
|
</list>
|
||||||
<recent_temporary>
|
<recent_temporary>
|
||||||
<list>
|
<list>
|
||||||
|
<item itemvalue="PHPUnit.RouterPartialGroupTest" />
|
||||||
<item itemvalue="PHPUnit.tests" />
|
<item itemvalue="PHPUnit.tests" />
|
||||||
<item itemvalue="PHPUnit.RouterRouteTest" />
|
<item itemvalue="PHPUnit.RouterRouteTest" />
|
||||||
<item itemvalue="PHPUnit.phpunit.xml" />
|
<item itemvalue="PHPUnit.phpunit.xml" />
|
||||||
<item itemvalue="PHP Script.debug.php" />
|
<item itemvalue="PHP Script.debug.php" />
|
||||||
<item itemvalue="PHPUnit.EventHandlerTest" />
|
|
||||||
</list>
|
</list>
|
||||||
</recent_temporary>
|
</recent_temporary>
|
||||||
</component>
|
</component>
|
||||||
@@ -525,6 +527,7 @@
|
|||||||
</entry>
|
</entry>
|
||||||
</map>
|
</map>
|
||||||
</option>
|
</option>
|
||||||
|
<option name="oldMeFiltersMigrated" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="XSLT-Support.FileAssociations.UIState">
|
<component name="XSLT-Support.FileAssociations.UIState">
|
||||||
<expand />
|
<expand />
|
||||||
|
|||||||
@@ -52,8 +52,16 @@ class RouteGroup extends Route implements IGroupRoute
|
|||||||
return false;
|
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 */
|
/* 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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,4 +25,49 @@ class RouterPartialGroupTest extends \PHPUnit\Framework\TestCase
|
|||||||
$this->assertEquals('param2', $result2);
|
$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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,7 @@ class TestRouter extends \Pecee\SimpleRouter\SimpleRouter
|
|||||||
static::start();
|
static::start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function debug($testUrl, $testMethod = 'get')
|
public static function debug($testUrl, $testMethod = 'get', bool $reset = true)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
static::debugNoReset($testUrl, $testMethod);
|
static::debugNoReset($testUrl, $testMethod);
|
||||||
@@ -22,17 +22,19 @@ class TestRouter extends \Pecee\SimpleRouter\SimpleRouter
|
|||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($reset === true) {
|
||||||
static::router()->reset();
|
static::router()->reset();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function debugOutput($testUrl, $testMethod = 'get')
|
public static function debugOutput($testUrl, $testMethod = 'get', bool $reset = true)
|
||||||
{
|
{
|
||||||
$response = null;
|
$response = null;
|
||||||
|
|
||||||
// Route request
|
// Route request
|
||||||
ob_start();
|
ob_start();
|
||||||
static::debug($testUrl, $testMethod);
|
static::debug($testUrl, $testMethod, $reset);
|
||||||
$response = ob_get_contents();
|
$response = ob_get_contents();
|
||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user