diff --git a/Slim/Routing/RouteParser.php b/Slim/Routing/RouteParser.php index 216175c6c..498048acc 100644 --- a/Slim/Routing/RouteParser.php +++ b/Slim/Routing/RouteParser.php @@ -125,4 +125,14 @@ public function fullUrlFor(UriInterface $uri, string $routeName, array $data = [ $protocol = ($scheme ? $scheme . ':' : '') . ($authority ? '//' . $authority : ''); return $protocol . $path; } + + /** + * Get base path + * + * @return string + */ + public function getBasePath(): string + { + return $this->routeCollector->getBasePath(); + } } diff --git a/tests/Routing/RouteParserTest.php b/tests/Routing/RouteParserTest.php index 109152f7c..3e1f3760e 100644 --- a/tests/Routing/RouteParserTest.php +++ b/tests/Routing/RouteParserTest.php @@ -194,4 +194,17 @@ public function testFullUrlFor() $expectedResult = 'http://example.com:8080/app/123'; $this->assertEquals($expectedResult, $result); } + + public function testGetBasePath() + { + $responseFactoryProphecy = $this->prophesize(ResponseFactoryInterface::class); + $callableResolverProphecy = $this->prophesize(CallableResolverInterface::class); + + $routeCollector = new RouteCollector($responseFactoryProphecy->reveal(), $callableResolverProphecy->reveal()); + $routeCollector->setBasePath('/app'); + + $routeParser = $routeCollector->getRouteParser(); + + $this->assertEquals('/app', $routeParser->getBasePath()); + } }