Skip to content

Commit 275abd4

Browse files
[FrameworkBundle] Allow configuring the default base URI with a DSN
1 parent aa0ed35 commit 275abd4

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ CHANGELOG
1212
* added `ExpressionLanguageProvider` to expose extra functions to route conditions
1313
* added support for a `stateless` keyword for configuring route stateless in PHP, YAML and XML configurations.
1414
* added the "hosts" option to be able to configure the host per locale.
15+
* added `RequestContext::fromUri()` to ease building the default context
1516

1617
5.0.0
1718
-----

RequestContext.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,23 @@ public function __construct(string $baseUrl = '', string $method = 'GET', string
4545
$this->setQueryString($queryString);
4646
}
4747

48+
public static function fromUri(string $uri, string $host = 'localhost', string $scheme = 'http', int $httpPort = 80, int $httpsPort = 443): self
49+
{
50+
$uri = parse_url($uri);
51+
$scheme = $uri['scheme'] ?? $scheme;
52+
$host = $uri['host'] ?? $host;
53+
54+
if (isset($uri['port'])) {
55+
if ('http' === $scheme) {
56+
$httpPort = $uri['port'];
57+
} elseif ('https' === $scheme) {
58+
$httpsPort = $uri['port'];
59+
}
60+
}
61+
62+
return new self($uri['path'] ?? '', 'GET', $host, $scheme, $httpPort, $httpsPort);
63+
}
64+
4865
/**
4966
* Updates the RequestContext information based on a HttpFoundation Request.
5067
*

0 commit comments

Comments
 (0)