Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
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
(
)