findAssetFromCache example

public function onKernelRequest(RequestEvent $event): void
    {
        if (!$event->isMainRequest()) {
            return;
        }

        $pathInfo = $event->getRequest()->getPathInfo();
        if (!str_starts_with($pathInfo$this->publicPrefix)) {
            return;
        }

        $asset = $this->findAssetFromCache($pathInfo);

        if (!$asset) {
            throw new NotFoundHttpException(sprintf('Asset with public path "%s" not found.', $pathInfo));
        }

        $mediaType = $this->getMediaType($asset->publicPath);
        $response = (new Response(
            $asset->content,
            headers: $mediaType ? ['Content-Type' => $mediaType] : [],
        ))
            ->setPublic()
            
Home | Imprint | This part of the site doesn't use cookies.