Skip to content

Commit

Permalink
Add $hash parameter to UrlGeneratorInterface methods (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik authored Feb 23, 2025
1 parent eceef11 commit fad6e6b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
- Bug #257: Explicitly mark nullable parameters (@vjik)
- Сhg #247: Change `UrlGeneratorInterface` contract: on URL generation all unused arguments must be moved to query
parameters, if query parameter with such name doesn't exist (@vjik)
- New #262: Add `$hash` parameter to `UrlGeneratorInterface` methods: `generate()`, `generateAbsolute()` and
`generateFromCurrent()` (@vjik)

## 3.1.0 February 20, 2024

Expand Down
9 changes: 7 additions & 2 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,10 @@ The following backward incompatible changes have been made.

### `UrlGeneratorInterface` changes

Contract is changed: on URL generation all unused arguments must be moved to query parameters, if query parameter with
such name doesn't exist. You should change your interface implementations accordingly.
Contract is changed:

- on URL generation all unused arguments must be moved to query parameters, if query parameter with
such name doesn't exist;
- added `$hash` parameter to `generate()`, `generateAbsolute()` and `generateFromCurrent()` methods.

You should change your interface implementations accordingly.
12 changes: 11 additions & 1 deletion src/UrlGeneratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@ interface UrlGeneratorInterface
* @param array $arguments Argument-value set. Unused arguments will be moved to query parameters, if query
* parameter with such name doesn't exist.
* @param array $queryParameters Parameter-value set.
* @param string|null $hash Hash part (fragment identifier) of the URL.
*
* @throws RouteNotFoundException In case there is no route with the name specified.
*
* @return string URL generated.
*
* @psalm-param UrlArgumentsType $arguments
*/
public function generate(string $name, array $arguments = [], array $queryParameters = []): string;
public function generate(
string $name,
array $arguments = [],
array $queryParameters = [],
?string $hash = null,
): string;

/**
* Generates absolute URL from named route, arguments, and query parameters.
Expand All @@ -36,6 +42,7 @@ public function generate(string $name, array $arguments = [], array $queryParame
* @param array $arguments Argument-value set. Unused arguments will be moved to query parameters, if query
* parameter with such name doesn't exist.
* @param array $queryParameters Parameter-value set.
* @param string|null $hash Hash part (fragment identifier) of the URL.
* @param string|null $scheme Host scheme.
* @param string|null $host Host for manual setup.
*
Expand All @@ -49,6 +56,7 @@ public function generateAbsolute(
string $name,
array $arguments = [],
array $queryParameters = [],
?string $hash = null,
string $scheme = null,
string $host = null
): string;
Expand All @@ -59,6 +67,7 @@ public function generateAbsolute(
* @param array $replacedArguments New argument values indexed by replaced argument names. Unused arguments will be
* moved to query parameters, if query parameter with such name doesn't exist.
* @param array $queryParameters Parameter-value set.
* @param string|null $hash Hash part (fragment identifier) of the URL.
* @param string|null $fallbackRouteName Name of a route that should be used if current route.
* can not be determined.
*
Expand All @@ -67,6 +76,7 @@ public function generateAbsolute(
public function generateFromCurrent(
array $replacedArguments,
array $queryParameters = [],
?string $hash = null,
?string $fallbackRouteName = null
): string;

Expand Down

0 comments on commit fad6e6b

Please sign in to comment.