Skip to content

Commit fad6e6b

Browse files
authored
Add $hash parameter to UrlGeneratorInterface methods (#262)
1 parent eceef11 commit fad6e6b

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
- Bug #257: Explicitly mark nullable parameters (@vjik)
1313
- Сhg #247: Change `UrlGeneratorInterface` contract: on URL generation all unused arguments must be moved to query
1414
parameters, if query parameter with such name doesn't exist (@vjik)
15+
- New #262: Add `$hash` parameter to `UrlGeneratorInterface` methods: `generate()`, `generateAbsolute()` and
16+
`generateFromCurrent()` (@vjik)
1517

1618
## 3.1.0 February 20, 2024
1719

UPGRADE.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,10 @@ The following backward incompatible changes have been made.
3737

3838
### `UrlGeneratorInterface` changes
3939

40-
Contract is changed: on URL generation all unused arguments must be moved to query parameters, if query parameter with
41-
such name doesn't exist. You should change your interface implementations accordingly.
40+
Contract is changed:
41+
42+
- on URL generation all unused arguments must be moved to query parameters, if query parameter with
43+
such name doesn't exist;
44+
- added `$hash` parameter to `generate()`, `generateAbsolute()` and `generateFromCurrent()` methods.
45+
46+
You should change your interface implementations accordingly.

src/UrlGeneratorInterface.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,20 @@ interface UrlGeneratorInterface
2020
* @param array $arguments Argument-value set. Unused arguments will be moved to query parameters, if query
2121
* parameter with such name doesn't exist.
2222
* @param array $queryParameters Parameter-value set.
23+
* @param string|null $hash Hash part (fragment identifier) of the URL.
2324
*
2425
* @throws RouteNotFoundException In case there is no route with the name specified.
2526
*
2627
* @return string URL generated.
2728
*
2829
* @psalm-param UrlArgumentsType $arguments
2930
*/
30-
public function generate(string $name, array $arguments = [], array $queryParameters = []): string;
31+
public function generate(
32+
string $name,
33+
array $arguments = [],
34+
array $queryParameters = [],
35+
?string $hash = null,
36+
): string;
3137

3238
/**
3339
* Generates absolute URL from named route, arguments, and query parameters.
@@ -36,6 +42,7 @@ public function generate(string $name, array $arguments = [], array $queryParame
3642
* @param array $arguments Argument-value set. Unused arguments will be moved to query parameters, if query
3743
* parameter with such name doesn't exist.
3844
* @param array $queryParameters Parameter-value set.
45+
* @param string|null $hash Hash part (fragment identifier) of the URL.
3946
* @param string|null $scheme Host scheme.
4047
* @param string|null $host Host for manual setup.
4148
*
@@ -49,6 +56,7 @@ public function generateAbsolute(
4956
string $name,
5057
array $arguments = [],
5158
array $queryParameters = [],
59+
?string $hash = null,
5260
string $scheme = null,
5361
string $host = null
5462
): string;
@@ -59,6 +67,7 @@ public function generateAbsolute(
5967
* @param array $replacedArguments New argument values indexed by replaced argument names. Unused arguments will be
6068
* moved to query parameters, if query parameter with such name doesn't exist.
6169
* @param array $queryParameters Parameter-value set.
70+
* @param string|null $hash Hash part (fragment identifier) of the URL.
6271
* @param string|null $fallbackRouteName Name of a route that should be used if current route.
6372
* can not be determined.
6473
*
@@ -67,6 +76,7 @@ public function generateAbsolute(
6776
public function generateFromCurrent(
6877
array $replacedArguments,
6978
array $queryParameters = [],
79+
?string $hash = null,
7080
?string $fallbackRouteName = null
7181
): string;
7282

0 commit comments

Comments
 (0)