BeforeSendResponseEvent example

$filteredRequest = parent::filterRequest($request);
        $transformedRequest = $this->requestTransformer->transform($filteredRequest);

        return $this->lastRequest = $transformedRequest;
    }

    /** * @param Response $response */
    protected function filterResponse(object $response): DomResponse
    {
        $event = new BeforeSendResponseEvent($this->lastRequest, $response);
        $this->eventDispatcher->dispatch($event);

        return parent::filterResponse($response);
    }
}
$subscriber = new CacheResponseSubscriber(
            $this->createMock(CartService::class),
            100,
            true,
            new MaintenanceModeResolver(new RequestStack()new CoreMaintenanceModeResolver(new EventDispatcher())),
            $reverseProxyEnabled,
            null,
            null
        );

        $subscriber->updateCacheControlForBrowser(new BeforeSendResponseEvent(new Request()$response));

        static::assertSame($afterHeader$response->headers->get('cache-control'));

        if (!$reverseProxyEnabled) {
            static::assertFalse($response->headers->has(CacheResponseSubscriber::INVALIDATION_STATES_HEADER));
        }
    }

    /** * @return array<string, array<int, bool|string|null>> */
    
// check for http caching         $enabled = $container->hasParameter('shopware.http.cache.enabled')
            && $container->getParameter('shopware.http.cache.enabled');
        if ($enabled && $container->has(CacheStore::class)) {
            $kernel = new static::$httpCacheClass($kernel$container->get(CacheStore::class), null, ['debug' => $this->debug]);
        }

        $response = $kernel->handle($transformed$type$catch);

        // fire event to trigger runtime events like seo url headers         $event = new BeforeSendResponseEvent($transformed$response);
        $container->get('event_dispatcher')->dispatch($event);

        return new HttpKernelResult($transformed$event->getResponse());
    }

    private function createKernel(): KernelInterface
    {
        if ($this->kernel !== null) {
            return $this->kernel;
        }

        
Home | Imprint | This part of the site doesn't use cookies.