References Router
Reference
C
Class

ApiPlatform\Symfony\Routing\Router

Symfony router decorator.

class ApiPlatform\Symfony\Routing\Router implements Symfony\Component\Routing\RouterInterface, ApiPlatform\Api\UrlGeneratorInterface, Symfony\Component\Routing\RequestContextAwareInterface, Symfony\Component\Routing\Generator\UrlGeneratorInterface, Symfony\Component\Routing\Matcher\UrlMatcherInterface
{
    public __construct(Symfony\Component\Routing\RouterInterface $router, int $urlGenerationStrategy)
    public setContext(Symfony\Component\Routing\RequestContext $context): null
    public getContext(): Symfony\Component\Routing\RequestContext
    public getRouteCollection(): Symfony\Component\Routing\RouteCollection
    public match(string $pathInfo): array
    public generate(string $name, array $parameters, null|int $referenceType): string
}

Methods

__construct

public __construct(Symfony\Component\Routing\RouterInterface $router, int $urlGenerationStrategy)

Parameters

routerSymfony\Component\Routing\RouterInterface
urlGenerationStrategyint

setContext

Sets the request context.Sets the request context.Sets the request context.Sets the request context.

public setContext(Symfony\Component\Routing\RequestContext $context): null

Parameters

contextSymfony\Component\Routing\RequestContext

Returns

null

getContext

Gets the request context.Gets the request context.Gets the request context.Gets the request context.

public getContext(): Symfony\Component\Routing\RequestContext

Returns

Symfony\Component\Routing\RequestContext

getRouteCollection

Gets the RouteCollection instance associated with this Router.WARNING: This method should never be used at runtime as it is SLOW. You might use it in a cache warmer though.

public getRouteCollection(): Symfony\Component\Routing\RouteCollection

Returns

Symfony\Component\Routing\RouteCollection

match

Tries to match a URL path with a set of routes.If the matcher cannot find information, it must throw one of the exceptions documented below.Tries to match a URL path with a set of routes.If the matcher cannot find information, it must throw one of the exceptions documented below.

public match(string $pathInfo): array

Parameters

pathInfostring

Returns

array

generate

Generates a URL or path for a specific route based on the given parameters.Parameters that reference placeholders in the route pattern will substitute them in the path or host. Extra params are added as query string to the URL.When the passed reference type cannot be generated for the route because it requires a different host or scheme than the current one, the method will return a more comprehensive reference that includes the required params. For example, when you call this method with $referenceType = ABSOLUTE_PATH but the route requires the https scheme whereas the current scheme is http, it will instead return an ABSOLUTE_URL with the https scheme and the current host. This makes sure the generated URL matches the route in any case.If there is no route with the given name, the generator must throw the RouteNotFoundException.The special parameter _fragment will be used as the document fragment suffixed to the final URL.Generates a URL or path for a specific route based on the given parameters.Parameters that reference placeholders in the route pattern will substitute them in the path or host. Extra params are added as query string to the URL.When the passed reference type cannot be generated for the route because it requires a different host or scheme than the current one, the method will return a more comprehensive reference that includes the required params. For example, when you call this method with $referenceType = ABSOLUTE_PATH but the route requires the https scheme whereas the current scheme is http, it will instead return an ABSOLUTE_URL with the https scheme and the current host. This makes sure the generated URL matches the route in any case.If there is no route with the given name, the generator must throw the RouteNotFoundException.The special parameter _fragment will be used as the document fragment suffixed to the final URL.Generates a URL or path for a specific route based on the given parameters.Parameters that reference placeholders in the route pattern will substitute them in the path or host. Extra params are added as query string to the URL.When the passed reference type cannot be generated for the route because it requires a different host or scheme than the current one, the method will return a more comprehensive reference that includes the required params. For example, when you call this method with $referenceType = ABSOLUTE_PATH but the route requires the https scheme whereas the current scheme is http, it will instead return an ABSOLUTE_URL with the https scheme and the current host. This makes sure the generated URL matches the route in any case.If there is no route with the given name, the generator must throw the RouteNotFoundException.The special parameter _fragment will be used as the document fragment suffixed to the final URL.

public generate(string $name, array $parameters, null|int $referenceType): string

Parameters

namestring
parametersarray
referenceTypeint

Returns

string

Made with love by

Les-Tilleuls.coop can help you design and develop your APIs and web projects, and train your teams in API Platform, Symfony, Next.js, Kubernetes and a wide range of other technologies.

Learn more

Copyright © 2023 Kévin Dunglas

Sponsored by Les-Tilleuls.coop