RequestFacade example


class RequestFacadeTest extends TestCase
{
    public function testUrl(): void
    {
        $request = new Request();
        $request->server->set('REQUEST_URI', '/foo/bar');
        $request->attributes->set('sw-original-request-uri', 'https://example.com/foo/bar');

        $facade = new RequestFacade($request);

        static::assertSame('https://example.com/foo/bar', $facade->uri());
    }

    public function testUrlOutsideStorefront(): void
    {
        $request = new Request();
        $request->server->set('REQUEST_URI', '/foo/bar');

        $facade = new RequestFacade($request);

        
class RequestFacadeFactory extends HookServiceFactory
{
    public function __construct(private readonly RequestStack $requestStack)
    {
    }

    public function factory(Hook $hook, Script $script): RequestFacade
    {
        $request = $this->requestStack->getMainRequest();
        \assert($request !== null);

        return new RequestFacade($request);
    }

    public function getName(): string
    {
        return 'request';
    }
}
Home | Imprint | This part of the site doesn't use cookies.