PHP Class Bolt\Canonical

- Provide a getter to get the canonical url for the current request. - Update the RequestContext with the scheme/host override from the config. Note: Updating the RequestContext also applies to the UrlGenerator.
Author: Carson Full ([email protected])
Inheritance: implements Symfony\Component\EventDispatcher\EventSubscriberInterface
Datei anzeigen Open project: bolt/bolt Class Usage Examples

Protected Properties

Property Type Description
$requestContext Symfony\Component\Routing\RequestContext
$requestStack Symfony\Component\HttpFoundation\RequestStack
$urlGenerator Symfony\Component\Routing\Generator\UrlGeneratorInterface

Public Methods

Method Description
__construct ( Symfony\Component\HttpFoundation\RequestStack $requestStack, Symfony\Component\Routing\RequestContext $requestContext, Symfony\Component\Routing\Generator\UrlGeneratorInterface $urlGenerator, string | null $override = null ) Constructor.
getSubscribedEvents ( )
getUrl ( ) : string | null Returns the canonical url for the current request, or null if called outside of the request cycle.
onRequest ( GetResponseEvent $event ) Sets the scheme and host overrides (if any) on the RequestContext.

Method Details

__construct() public method

Constructor.
public __construct ( Symfony\Component\HttpFoundation\RequestStack $requestStack, Symfony\Component\Routing\RequestContext $requestContext, Symfony\Component\Routing\Generator\UrlGeneratorInterface $urlGenerator, string | null $override = null )
$requestStack Symfony\Component\HttpFoundation\RequestStack
$requestContext Symfony\Component\Routing\RequestContext
$urlGenerator Symfony\Component\Routing\Generator\UrlGeneratorInterface
$override string | null An optional scheme/host override.

getSubscribedEvents() public static method

public static getSubscribedEvents ( )

getUrl() public method

Returns the canonical url for the current request, or null if called outside of the request cycle.
public getUrl ( ) : string | null
return string | null

onRequest() public method

This needs to happen after RouterListener as that sets the scheme and host from the request. To override we need to be after that.
public onRequest ( GetResponseEvent $event )
$event Symfony\Component\HttpKernel\Event\GetResponseEvent

Property Details

$requestContext protected_oe property

protected RequestContext,Symfony\Component\Routing $requestContext
return Symfony\Component\Routing\RequestContext

$requestStack protected_oe property

protected RequestStack,Symfony\Component\HttpFoundation $requestStack
return Symfony\Component\HttpFoundation\RequestStack

$urlGenerator protected_oe property

protected UrlGeneratorInterface,Symfony\Component\Routing\Generator $urlGenerator
return Symfony\Component\Routing\Generator\UrlGeneratorInterface