Skip to content

Commit

Permalink
Add URL arguments' psalm type in UrlGeneratorInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Jan 24, 2024
1 parent cd98ba6 commit f70156e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
16 changes: 12 additions & 4 deletions src/UrlGeneratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,41 @@

/**
* `UrlGeneratorInterface` allows generating URL given route name, arguments, and query parameters.
*
* @psalm-type ArgumentType = scalar|Stringable|null
* @psalm-type ArgumentsType = array<string, ArgumentType>
*/
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 ArgumentsType $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 ArgumentsType $arguments
*/
public function generateAbsolute(
string $name,
Expand All @@ -48,11 +55,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 ArgumentsType $replacedArguments
*/
public function generateFromCurrent(
array $replacedArguments,
Expand Down

0 comments on commit f70156e

Please sign in to comment.