Skip to content

Commit

Permalink
Add URL arguments' psalm type in UrlGeneratorInterface (#229)
Browse files Browse the repository at this point in the history
* Add URL arguments' psalm type in `UrlGeneratorInterface`

* improve
  • Loading branch information
vjik committed Jan 24, 2024
1 parent cd98ba6 commit 5bc9a72
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@
- Chg #207: Replace two `RouteCollectorInterface` methods `addRoute()` and `addGroup()` to single `addRoute()` (@vjik)
- Enh #202: Add support for `psr/http-message` version `^2.0` (@vjik)
- Chg #222: Make `Route`, `Group` and `MatchingResult` dispatcher-independent (@rustamwin, @vjik)
- Enh #229: Add URL arguments' psalm type in `UrlGeneratorInterface` (@vjik)

## 3.0.0 February 17, 2023

Expand Down
15 changes: 11 additions & 4 deletions src/UrlGeneratorInterface.php
Expand Up @@ -8,34 +8,40 @@

/**
* `UrlGeneratorInterface` allows generating URL given route name, arguments, and query parameters.
*
* @psalm-type UrlArgumentsType = array<string,scalar|Stringable|null>
*/
interface UrlGeneratorInterface
{
/**
* Generates URL from named route, arguments, and query parameters.
*
* @param string $name Name of the route.
* @param array<string,scalar|Stringable|null> $arguments Argument-value set.
* @param array $arguments Argument-value set.
* @param array $queryParameters Parameter-value set.
*
* @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;

/**
* Generates absolute URL from named route, arguments, and query parameters.
*
* @param string $name Name of the route.
* @param array<string,scalar|Stringable|null> $arguments Argument-value set.
* @param array $arguments Argument-value set.
* @param array $queryParameters Parameter-value set.
* @param string|null $scheme Host scheme.
* @param string|null $host Host for manual setup.
*
* @throws RouteNotFoundException In case there is no route with the name specified.
*
* @return string URL generated.
*
* @psalm-param UrlArgumentsType $arguments
*/
public function generateAbsolute(
string $name,
Expand All @@ -48,11 +54,12 @@ public function generateAbsolute(
/**
* Generate URL from the current route replacing some of its arguments with values specified.
*
* @param array<string,scalar|Stringable|null> $replacedArguments New argument values indexed by replaced argument
* names.
* @param array $replacedArguments New argument values indexed by replaced argument names.
* @param array $queryParameters Parameter-value set.
* @param string|null $fallbackRouteName Name of a route that should be used if current route.
* can not be determined.
*
* @psalm-param UrlArgumentsType $replacedArguments
*/
public function generateFromCurrent(
array $replacedArguments,
Expand Down

0 comments on commit 5bc9a72

Please sign in to comment.