Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding RouteParser::getBasePath method #2852

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions Slim/Interfaces/RouteParserInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,11 @@ public function urlFor(string $routeName, array $data = [], array $queryParams =
* @return string
*/
public function fullUrlFor(UriInterface $uri, string $routeName, array $data = [], array $queryParams = []): string;

/**
* Get base path
*
* @return string
*/
public function basePath(): string;
}
8 changes: 8 additions & 0 deletions Slim/Routing/RouteParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,12 @@ public function fullUrlFor(UriInterface $uri, string $routeName, array $data = [
$protocol = ($scheme ? $scheme . ':' : '') . ($authority ? '//' . $authority : '');
return $protocol . $path;
}

/**
* {@inheritdoc}
*/
public function basePath(): string
{
return $this->routeCollector->getBasePath();
}
}
13 changes: 13 additions & 0 deletions tests/Routing/RouteParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,17 @@ public function testFullUrlFor()
$expectedResult = 'http://example.com:8080/app/123';
$this->assertEquals($expectedResult, $result);
}

public function testBasePath()
{
$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->basePath());
}
}